Customizing recent posts

Hello X,

How would I go about customizing the recent posts to include my custom post types?

I have tried inserting this code in my functions.php

$args = array(
	'numberposts' => 10,
	'offset' => 0,
	'category' => 0,
	'orderby' => 'post_date',
	'order' => 'DESC',
	'include' => '',
	'exclude' => '',
	'meta_key' => '',
	'meta_value' =>'',
	'post_type'  => array('post','in_my_opinion','did_you_know'),
	'post_status'  => 'publish',
	'suppress_filters' => true
);

$recent_posts = wp_get_recent_posts( $args, ARRAY_A );

Hi Wilfried,

Please follow the instructions in this thread:

Hope this helps.

1 Like

I think I’ve got it. I need to use the recent posts shortcode.

Let me try that

Hey Wilfried,

Yes that’s correct, let us know how this goes.

Cheers!

It’s not going great.

The drag and drop is not working in cornerstone

Forgot to add section
Sorry, it’s been a while

Now I need your help guys
I am only fetching a max of 4 posts out of like 16 and none of them is one of my custom post types.

How do i deal with this?

Got it. I added this code
// Add post type to recent post element
function add_event_post_type( $types ) {
$types[‘in_my_opinion’] = ‘in_my_opinion’;
$types[‘did_you_know’] = ‘did_you_know’;
return $types;
}
add_filter( ‘cs_recent_posts_post_types’, ‘add_event_post_type’, 999 );

Works but It is not what I want for this particular page. I want all recent posts from all the types fetched at once and paginated.

Can I do that?

Hi @wmmajaliwa,

You can try with the offset attribute of recent posts shortcode:

[recent_posts count="4" type="in_my_opinion" orientation="horizontal"] [recent_posts count="4" type="in_my_opinion" orientation="horizontal" offset="4"]

http://demo.theme.co/integrity-1/shortcodes/recent-posts/

Hope it helps :slight_smile:

1 Like

Hi, Thai

I don’t see how to edit the shortcode the way you have typed it

This is what I see and it’s not working as i think it should

Hi Wilfried,

For shortcodes, you will have to type in the actual shortcode and add to either a Raw Content or a Text element and not the actual Recent Post element.

Hope this helps.

1 Like

Ah, excellent. Thank you, Jade

You’re welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.