Page with custom query
-
I would like to make a page template with a custom query where I want to query mutliple categories as one query.
This is my code `
<?php
$paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1;$custom_args = array(
‘post_type’ => ‘post’,
‘posts_per_page’ => 5,
‘category__and’ => array( 193,192,191 ) ,
‘paged’ => $paged
);$custom_query = new WP_Query( $custom_args ); ?>
<?php if ( $custom_query->have_posts() ) : ?>
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
<?php get_template_part( ‘content’, ‘pagecat’ ); ?>
<?php endwhile; // end of the loop. ?>
<?php
if (function_exists(custom_pagination)) {
custom_pagination($custom_query->max_num_pages,””,$paged);
}
?><?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( ‘Sorry, no posts matched your criteria.’ ); ?></p>
<?php endif; ?>`
It’s not working though. The categories are subcategories. Does this not work with subcategories? I thought as they have a unique ID..
Thanks for any help!
- The topic ‘Page with custom query’ is closed to new replies.