Skip Navigation

[Resolved] Limit by custom taxonomy in theme functions file

This support ticket is created 4 years, 12 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.

This topic contains 1 reply, has 1 voice.

Last updated by bobA-2 4 years, 12 months ago.

Author
Posts
#1434597

I have a view where I control the output by custom taxonomy based on query filter

Select posts with taxonomy:
TV channels slug in one of those set by the View shortcode attribute wpvtvchannels
eg. [wpv-view name="view-name" wpvtvchannels="xxxx"]

But I want the user to be able to do a front end search like this too:

Select posts with taxonomy:
TV channels slug in one of those set by the URL parameter wpvtvchannels
eg. hidden link

So I thought about making a function in my Theme functions file to prefilter the view with the channels I want included in the view.
Could you provide a sample of how this could be done?

From searching the forum here I found this:

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

if( $view_id == 273888) {

$query_args['tax_query'][] = array(
array(
'taxonomy' => 'tvchannels',
'field' => 'slug',
'terms' => 'channel4'
)
);

}
return $query_args;
}

But how do I add more than one term in the code?

If I just do the set by the URL parameter I get channels included that I do not want for this particular view.

#1434615

My issue is resolved now. Thank you!

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

if( $view_id == 273888) {

$query_args['tax_query'][] = array(
array(
'taxonomy' => 'tvchannels',
'field' => 'slug',
'terms' => array( 'channel4', 'channel5', 'channel6' )
)
);

}
return $query_args;
}