Anonymous User 15646442
(@anonymized-15646442)
Set include_children to false:
$query = new WP_Query( array(
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'your-category-slug',
'include_children' => false,
),
),
) );
Thread Starter
yortem
(@yortem)
it doesnt work. this is the code i have now (someone that helped me gave me this code to solve another problem i had)
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
$archive_args = array(
'post_type' => 'products', // get only products
'category__in' => $current_cat,
'posts_per_page' => 12,
'include_children' => false,
'paged' => $paged,
);
$archive_query = new WP_Query( $archive_args );
i dont see the children posts. but i see the number of pages when there are no posts in the main category
-
This reply was modified 6 years, 7 months ago by yortem.
Anonymous User 15646442
(@anonymized-15646442)
On which WordPress web files did you placed the above code? If it’s in the functions.php, you can try using the pre_get_posts hook as shown below.
add_action( 'pre_get_posts', 'my_archives_get_posts' );
function my_archives_get_posts( $query ) {
$archive_args = array(
'post_type' => 'products', // get only products
'category__in' => $current_cat,
'posts_per_page' => 12,
'include_children' => false,
'paged' => $paged,
);
$archive_query = new WP_Query( $archive_args );
}