I have a custom post types called photo gallery. In that post type I have registered a taxonomy called video. Then i have created two category under video called ‘personal’ & ‘commercial’. Now i want to show only the commercial category post to a page section. How can I do that? Here is the code I have tried but not working
<?php
$args = array(
'post_type'=>'photo_gallerys',
'post_status'=>'publish',
'video'=>'commercial',
'posts_per_page'=>-1,
'paged'=>get_query_var('paged')
);
// the query
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Try this code hope you’ll find your solution
if you want to get posts from category slug then use this code in tax_query array
use
'cat' => "your_cat_id
in your wp query argument.for example if I want to display post for only commercial category and commercial have
category id 21
, then I will write query to display post like this: