06/06/2014 by Nitesh

How To Get All Posts of a Specific Custom Post Type in WordPress

Friends,

In our last post, we saw how can we get a list of all custom post types registered in our WordPress installation. In this post, we will see how we can get a list of all posts of a specific custom post type in WordPress. This may come handy when you are creating an archive page of your custom post type or writing a custom search module for your WordPress site.

Let us assume we want to display all posts of custom post type named “product”. To display posts, we will use the below code –

$args = array(
             'showposts' => 10,
             'post_type' => 'product',
        );
$posts = new WP_Query($args);

Keep Learning and Sharing!Cheers!

#Custom Post Types#PhP#WordPress