Skip Navigation

[Resolved] Display all posts from 1 taxonomy.

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

Problem:
Display all posts from 1 taxonomy. - prefilter view results by filtering view results with taxonomy terms

Solution:
You should try to use the hook "wpv_filter_query" to pre-filter your view results by specific terms.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/display-all-posts-from-1-taxonomy/#post-1227954

Relevant Documentation:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created 5 years, 8 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 17 replies, has 2 voices.

Last updated by lewisP 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1228482

Minesh
Supporter

Languages: English (English )

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

Well - you have done all correct things but there were two issues.

- You forget to ACTIVATE the code snippet "food-drink-custom-code" 🙂
- You should use different function name for each filter you add. I changed the function name as "func_prefilter_food_drink_taxonomy":

add_filter( 'wpv_filter_query', 'func_prefilter_food_drink_taxonomy', 99, 3 );
function func_prefilter_food_drink_taxonomy( $query_args, $view_settings, $view_id ) {

   $display_view_ids = array(2481);
     
    if (in_array($view_id,$display_view_ids) and empty($query_args['tax_query']) ){
      
      
      	 $query_args['tax_query'] = array(array(
                    'taxonomy'=> 'food-drink-type',
                    'field' => 'id',
                    'terms' => array(69,70,65,74,68,66,76),
                    'operator' => 'IN',
                    'include_children' => 1
                ));
		
    }
    return $query_args;
}

I can see its working 🙂

#1228495

Minesh
Supporter

Languages: English (English )

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

Please feel free to resolve the ticket 🙂

#1228514

My issue is resolved now. Thank you!
Many thanks for you patience Minesh.