Custom Post Types in Latest News Widget


#1

Hey, I really like the Latest News Widget. However I would love to put custom post types in there instead of standard posts. Is there any way to do that?

Thanks.


#2

Hello there,

Thank you for asking.

In order to achieve that objective, I thought you would need to edit its post query which is specified in widgets/fp-latest-news.php file. Edit this file on your code editor, then find the following code block.

$r = new WP_Query( array(
	'no_found_rows'       => true,
	'post_status'         => 'publish',
	'category_name'       => $category,
	'posts_per_page'      => $number,			
) );

Then add post_type parameter.

$r = new WP_Query( array(
	'no_found_rows'       => true,
	'post_status'         => 'publish',
	'category_name'	      => $category,
	'posts_per_page'      => $number,	
        'post_type'           => 'your_cpt_slug',  		
) );

Replace your_cpt_slug to your post type slug.

P.S.

As you are editing the core theme’s file, you should take at your own risk. The changes you have made will be overridden once the theme gets updated in the future.

Regards,
Kharis


#3

That works great, thanks! I actually like the latest news widget better as a portfolio for my projects than the portfolio plugin.


#4

Hello there,

Thank you for updating me.

I am glad to know that it works.

Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

Regards,
Kharis