How to fetch Custom Post from wordpress

We can fetch custom post same like pages and post, the only difference is we have mention post type to fetch.

Here’s my code :-

Here my custom post is product which i was created in WordPress admin panel to use for products and i am only fetching publish post from WordPress admin panel.post_per_page -1 means it will fetch all product post can give limit to some number of record if required.


$type = 'products';


'post_type' => $type,

'post_status' => 'publish',

'posts_per_page' => -1


$my_query = new WP_Query($args);

if( $my_query->have_posts() ) {

while ($my_query->have_posts()) : $my_query->the_post(); ?>

<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>






Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s