Skip Navigation

[Resolved] In View Search if we put a Taxonomy filter in front-end we are forced to "and"?

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 5 replies, has 2 voices.

Last updated by Minesh 5 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2701295

Hello, I have an important problem with archive pages. In a project built with Toolset I need to place a front-end taxonomy in the search or filter field. The problem to do this changes the logic of everything to "and"

I need the view to show the Custom Post Type for two taxonomy in "or" and add what the user selects in "and"

I can think of some solutions but extraordinarily complex and difficult, perhaps there is a simple path, after all it is something that has surely happened to more people

#2701323
Please help.png

Attached example screenshot, filter in view

Please help

#2701394

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

What if you try to click on the "Edit" button you see with the screenshot you shared with your previous reply:
- https://toolset.com/forums/topic/in-view-search-if-we-put-a-taxonomy-filter-in-front-end-we-are-forced-to-and/#post-2701323

And then try to select "OR" from the "Taxonomy relationship:" section and save your view.

Please check the following screenshot:
- hidden link

#2701456
Problem with taxonomy as filter2.png
Problem with taxonomy as filter1.png

That's what I mean, it's not possible

To be 100% sure I did a clean installation locally. I also follow the example of the documentation gyms. To replicate the error I have created 3 taxonomies for "gyms"

- Service
- Additional Service
- City

I have created 2 gyms in two cities. One with the "Personal Training" service included and the other as an "Additional Service"

I have created a "Personal Training" page where I am going to show the two types of service and the user can filter the city

(Gym1 offer Personal Training in service and Gym2 as adiditional service)

If I place "or" for a second visually "city" disappears and appears as if it were effective.

But it's just a visual thing, if you reselect the view block you see the real filter that is being applied

The final page does not show a result, since everything is forced in "and" it would show custom post type that have the service as included and as additional at the same time

Can it be considered a bug? How long can it take to be repaired?

Thanks greetings

#2701639

Please help. I need the information to make decisions

#2701870

Minesh
Supporter

Languages: English (English )

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

What if you try to use the following filter hook to fix your issue.

You can add the following code to "Custom Code" offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

function func_set_tax_relation_to_or($view_args, $view_settings, $view_id) {

$target_view_ids = array( 99999);

if (in_array($view_id, )) { 

        if ( isset( $view_args['tax_query'] ) ) {
                      $view_args['tax_query']['relation'] = 'OR';
        }
}

return $view_args;
}
add_filter('wpv_filter_query', 'func_set_tax_relation_to_or', 101, 3);

Where:
Replace 99999 with your original view ID.

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#2701965

Thanks for the proposal, it looks interesting, in the project I'm working on it was too complex to implement (too many views and too many taxonomies), I took another path

It is difficult to explain the path I took, in the form for the custom post type I have created generic fields that in value can build the slug of the taxonomy, so that when the user fills out the form they join the taxonomy. My approach is also complex and difficult, but I can freely place those custom fields as a filter

It would be great in the future to be able to use taxonomies as filters without changing the logic of everything to "and"