WordPress.org

Ready to get started?Download WordPress

Forums

Sub-category post displayed category archive (4 posts)

  1. adeara
    Member
    Posted 1 year ago #

    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

  2. adeara
    Member
    Posted 1 year ago #

    My site is hatsglobally.com

  3. adeara
    Member
    Posted 1 year ago #

  4. vjpo
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic