How to Query Custom post types with taxonomy or without taxonomy

Shortlink:

Today i will teach you how to query custom post types with taxonomy or without taxonomy

 

With Taxonomy support

<?php
$postquery_call = new WP_Query(array(
'post_type' => 'testimonial',
'post_per_pages' => -1,

'tab_category' => 'your category  name' ,

)) ;

?>
<?php while($postquery_call->have_posts()) : $postquery_call->the_post();?>

//your content

<?php endwhile;?>

You can see tab_category in above codes, you can understand this is type of your register taxonomy, and your category name is your taxonomy name example: slider

If you want to query only post without taxonomy call then just remove this line in above codes ‘tab_category’ => ‘your category  name’ 

 

And if you use foreach functions then you can use below codes

Way Two, Query using foreach function

 


<?php
global $post;
$args = array( 'posts_per_page' => -1, 'post_type'=> 'testimonial', 'tab_category'=>'your category name');
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>

// Your content
<?php endforeach; ?>

You can see tab_category in above codes, you can understand this is type of your register taxonomy, and your category name is your taxonomy name example: slider

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!




%d bloggers like this: