Support » Fixing WordPress » Sub-category post displayed category archive

  • adeara

    (@adeara)


    Hello house, I want somebody to help me out of this problem, the problem is that subcategory post display on my site whenever a category is clicked. What I am trying to say is that i have parent category A with post in it, and it has some subcategories with post in them. If a visitor should click on category A, instead to display its post, it will display the post in subcategory and this is misleading. Is there anybody with ideal of what I can do to correct this? Some of the prescribe solution I saw online did not work for me, may be because I use twenty ten theme. My website is

Viewing 3 replies - 1 through 3 (of 3 total)
  • adeara

    (@adeara)

    My site is hatsglobally.com

    adeara

    (@adeara)

    vjpo

    (@vjpo)

    function no_sub_in_category_archive( $query ) {
        if ( ! is_admin() && $query->is_main_query() && $query->is_category() )
            $query->set( 'category__in', array( get_queried_object_id() ) );
    }
    add_action( 'pre_get_posts', 'no_sub_in_category_archive' );

    Try to add this snippet into theme’s functions.php
    It takes posts only from queried category, not from children categories.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sub-category post displayed category archive’ is closed to new replies.