Recent Posts widget is one of default widgets that ships with WordPress. It allows you to display a number of your recent posts on the sidebar or any widgetized location of your site.
While working on a project, we needed to display recents items from a Custom Post Type (CPT). While there a few available plugins out there to display recent items from CPT, we wanted a simple solution.
Luckily, there is widget_posts_args
filter available. Here’s a working snippet you can copy and paste it into your functions.php file.
1 2 3 4 5 6 7 8 |
|
Hat tip to Dan Stefanchu for this awesome code snippet.
As you can see from the code above, we’d like to diaplay recent items from Themes CPT. However, if you’d like to display items from normal Post type and CPT, you may write them in an array like this:
$params['post_type'] = array( 'post, 'themes' );
We hope this tutorial will be useful for those of you who are looking a simple way to display recent items from CPT. For more awesome tutorials, don’t forget to subscribe to our RSS and follow us on Twitter and Google+.
Leave a Reply