• hi, i changed my archives to display only the posts that are directly under the current category and not to display posts under subcategories. but somehow i still see the full navigation like it’s count all the posts.

    for example.
    main category (with 3 posts) > sub category (with 15 posts)
    in main category i see 2 pages, even tho its only display 3 posts. it just count 18 posts probably.

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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 );
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I see navigation when not needed’ is closed to new replies.