Skip Navigation

[Resolved] List of posts from specific taxonomy, exclude ones from child taxonomies

This thread is resolved. Here is a description of the problem and solution.

Problem:
List of posts from specific taxonomy, exclude ones from child taxonomies

Solution:
You need to use view's filter hook wpv_filter_query in order to modify view's query on fly.

You can find the proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/list-of-posts-from-specific-taxonomy-exclude-ones-from-child-taxonomies/#post-1218373

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Annie 5 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1217317

I'm trying to output a hierarchical list with Document Categories (a custom taxonomy), and the Documents (custom post type) listed within them (via Parent View Taxonomy filter). I have it set up with a View to output the categories, which includes another view that outputs the Documents.

The problem I'm having is, each time the Documents view is called, it's also including the Documents from the child-taxonomies of the one it's supposed to be pulling. So it ends up listing the Documents multiple times, like this:

Category 1
- Document A
- Document B
- Document C
- Category 1-A
- - Document B
- - Document C
- - Category 1-A-1
- - - Document C

What I want is for it to only output each Document at it's deepest level, so like this:

Category 1
- Document A
- Category 1-A
- - Document B
- - Category 1-A-1
- - - Document C

Is there some way to get the Documents View to only list the Documents from the specific taxonomy, and not include Documents from the child taxonomies of it?

#1217593

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I need to check on your install how you configured your view.

- Can you please share the problem URL where I can check your issue?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1218373

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now:
=> hidden link

You need to use view's filter hook wpv_filter_query in order to modify view's query on fly.
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

I've added the following code to Toolset's "Custom code" section:

add_filter( 'wpv_filter_query', 'func_exclue_child_terms_posts', 10, 3 );
function func_exclue_child_terms_posts( $query_args, $settings, $view_id ) {
        if($view_id == 4055){
             $query_args['tax_query'][0]['include_children'] = 0;
              
    }
    return $query_args;
}

=> hidden link

More info:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1218379

Perfect, thanks!