Skip Navigation

[Resolved] Problem to filter content in view (I would like to join two taxonomies)

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#2605371

Hi, I'm working on positioning various custom taxonomies

The issue is that these taxonomies have a very similar secondary taxonomy (but different enough for the user) and I would like to include them in the page that I am about to position (I would like to work it as a normal page to have maximum freedom)

The ideal way would be to be able to work this from the same View, so that the user can filter the secondary taxonomy or create a nested view, so that the filters that the user selects are applied to both views.

The first option does not seem valid, since if one filters the content using Query Filters, creating a Search Field of the same taxonomy generates a conflict. I tried the second option to nest a view but I get a message "Nested views creation is not supported at the moment."

Can I do something to work with nested views? What would you recommend for this situation? I know there are easier ways (after all, that's what archive pages are for) but I would like to know if there is a way to unify both taxonomies and apply filters simultaneously

Thank you !

Greetings

#2605555

Hi,

Thank you for contacting us and I'd be happy to assist.

The nesting of views is supported, but only when using the classic/legacy views editor.
( ref: https://toolset.com/documentation/legacy-features/views-plugin/using-a-child-view-in-a-taxonomy-view-layout/ )

To turn on the classic/legacy views editor, please go to WP Admin -> Toolset -> Settings -> General and select "Show both the legacy and Blocks interface and let me choose which to use for each item I build" for the "Editing experience" field.

After that, you'll be able to create new views from WP Admin -> Toolset -> Views.

The documentation for the classic/legacy editor's features is available at:
https://toolset.com/documentation/legacy-features/views-plugin/

To make the requirement more clear, can you please share some names of the primary and secondary terms and the related pages that you're planning to use? I'll be in a better position to suggest an efficient structure, accordingly.

regards,
Waqar

#2605673

Thank you very much, I'm going to do tests locally before making the changes on the real web

For example here I have a taxonomy that I do want to position (I altered or simplified the URL, but it is a Toolset taxonomy)

hidden link

And here I have a child taxonomy that I'm not going to position, but whose content I'd like to insert into the first taxonomy

hidden link

My intention is to overwrite the archive page with a common page, to have maximum design freedom. In this example, simply create a page whose slug is bailes-eroticos

All these taxonomies are noindex yet, so any advice or recommendation is very welcome

Thanks again
Greetings

#2605695

I meant secondary taxonomy, not child taxonomy (I chose the wrong words and can cause confusion). I needed them to have different position and different anchor text, so I had to create a separate taxonomy, both taxonomies are labels without hierarchies and have no backend relationship

#2605815

I have done many tests locally, I am about to give up. Using legacy blocks I was able to nest a view but I get to a very similar point as with modern blocks

Going back to modern blocks, my ideal way would be to set a Query filter with the OR condition with both taxonomies and the user decides to show or hide those same taxonomies in front-end

From what I understand it is not possible to do this, since it is not possible to use the taxonomies in backend and front-end at the same time. In addition, from the tests I have carried out, I can see that the filter relationship is forced to AND when there is a filter in the front-end (in other words, the user filters will always be to reach a more specific result)

I am not able to see many solutions, I really need a hand. The other alternative is to simply place two views on the same page, although it is inconvenient for the user, since they will have to repeat the filters they selected in the first view

#2606579

Thanks for writing back and sharing this update.

If you place two views on the same page, that listen to the same URL parameter for the two different taxonomies in the respective query filter settings, then a single search form can be used to update the search results of both views.

Note: Please make sure that the views are set to update the result without the AJAX and the page reloads, when the search is performed.

It's the closest possible solution that I can think of and let me know how it goes.

#2606717

Thank you very much for the answer, I'm still doing tests locally (this part has been quite hard for me)

In local I have managed to replicate the recommended proposal (but in the secondary view I was forced to put the same search fields, but I can hide them with CSS and everything seems to work fine)

I continued testing with the legacy blocks nesting both views, it caught my attention that AJAX can be applied to the entire page. With legacy blocks I can use AJAX loading for both views

But to be honest with myself it would be too hard for me to work with shortcodes, I think it's too heavy for those who are used to modern blocks

Right now I'm fine with the proposed alternative, it's something I can do in a reasonable amount of time and I have a lot of control over what is seen on the front-end

One last question, just to consider for future optimizations. Would it be possible to join both views with functional filters? Is there documentation of someone trying to do something similar? I don't want to do it right now, but if possible I'd like to consider it for the future

By the way I have also noticed that the query filters are changed to AND mode when there is a front-end filter. So if the previous Query filters were exclusive, the view will always show that no results were found. It would be great to be able to set query filters in OR mode and have the filters selected by the user be in AND mode

Thanks again for your patience and guidance

#2607285

Sorry, I got confused, it is possible to apply two filters in OR mode and for the front-end user to apply filters in AND mode (at one point I did so many tests that I got confused myself)

The conflict happens only when one tries to apply the same filter on the backend and front-end at the same time. Anyway I would appreciate a little comment or direction for an implementation that solves this problem (filtering or showing the same taxonomies on backend and frontend at the same time)

#2607819

Glad that you've been making progress.

> One last question, just to consider for future optimizations. Would it be possible to join both views with functional filters? Is there documentation of someone trying to do something similar? I don't want to do it right now, but if possible I'd like to consider it for the future

- For programmatically filtering the view's results, you can use the 'wpv_filter_query' filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

And yes, you can use the same filtering function to target multiple views, by checking for the multiple target view IDs.

For example, suppose your target view IDs are '123', '456', and '789'. The custom filtering function's structure will look like this:


add_filter( 'wpv_filter_query', 'custom_filter_func', 1000 , 3 );
function custom_filter_func( $query_args, $view_settings ) {
	// target view IDs
	$view_ids_array = array(123, 456, 789); 
	// check if not in the admin area and the view is one of the target views
	if ( !is_admin() && isset($view_settings['view_id']) && in_array($view_settings['view_id'], $view_ids_array) ) {
		// do custom processing
	}
	return $query_args;
}

> By the way I have also noticed that the query filters are changed to AND mode when there is a front-end filter. So if the previous Query filters were exclusive, the view will always show that no results were found. It would be great to be able to set query filters in OR mode and have the filters selected by the user be in AND mode

- To change the relations operator between the multiple custom fields filter from "AND" to "OR", you can again use the "wpv_filter_query" filter:


add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
    // process if specific view
    if ( ( isset($view_settings['view_id']) && $view_settings['view_id'] == 1234) ) {
        if( !empty($query_args['meta_query']) ) {
            $query_args['meta_query']['relation'] = 'OR';
        }
    }
    return $query_args;
}

Note: Please replace '1234' with the actual ID of your target view.

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

> The conflict happens only when one tries to apply the same filter on the backend and front end at the same time.

- Your observation is correct. You can either set a static/fixed query filter in the view's 'Query Filter' section or let it be controlled through the frontend search field filters. But, it is not possible to have both at the same time for the custom fields or taxonomies.

#2607981

Thank you very much, I am learning and saving the code snippets

Finally I have chosen to work with a single view. Occupying two views worked, but it had some disadvantages (not being able to use AJAX, to maintain functionality the visible filters had to show all the available fields, many situations were generated in which the views ran out of data to display). Working with a single view offers a more modern, simple and fast interface

What I have done is simply mark in a conditional block with a message the custom post types that belong to the secondary taxonomy

I would appreciate it if you could check an example close to being finished:

hidden link

The ideal result would be to be able to hide the second taxonomy with a chexbox. Considering that it is a normal page with a normal view (2 taxonomies in query filter). What I would have to do is include a taxonomy in the filter, which will generate a conflict but could it be corrected with the last proposed filter? As simple as that? The only detail that would remain to be covered is the fact that when inserting the taxonomy filter in the front-end it will show all the taxonomies, when it would be convenient to only show the secondary taxonomy

Again, thank you very much

#2608025

Thank you for sharing this.

I'll have to see exactly how these views are set up in the admin area, to suggest if we can further make this get closer to your requirement.

Can you please share temporary admin login details in reply to this message?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2608291

For now I'm fine, I would really like to do it, but prioritizing times I prefer to focus on finishing the seo optimization and then implement that filter

Thank you very much for the guidance and alternatives. I've learned and maybe I'll be able to finish the implementation myself with the provided code snippets

Greetings !