The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Sub-category post displayed category archive (4 posts)

  1. adeara
    Posted 3 years 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
    Posted 3 years ago #

    My site is hatsglobally.com

  3. adeara
    Posted 3 years ago #

  4. vjpo
    Posted 3 years 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