Skip Navigation

[Resolved] Prefilter filters on term archive page

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

Our next available supporter will start replying to tickets in about 0.33 hours from now. Thank you for your understanding.

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: Africa/Casablanca (GMT+01:00)

This topic contains 16 replies, has 2 voices.

Last updated by romanB-3 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#1686931

Hi,
I have an Archive view applied to "Domaine" taxonomy, and some filters on this view in order to allow the user to filter results.
But those filters display all options, even if I set the view to hide options with no results.
hidden link
How may I correct this ?
Thank you.

#1687353

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

I tested this on a clean install and I was not able to reproduce it with a custom post type, a custom taxonomy, and a blocks based archive template. my custom field filter only displays the values available from the results.

Please make sure to update Toolset plugins to the latest release. Then, check if this issue appears when:
- Only Toolset plugins are activated. It will tell us if there is an interaction issue with another plugin.
- The theme is set to a WordPress default like Twenty Fourteen. It will tell us if there is an interaction issue with your theme.
If the problem disappears, start activating one at the time to track where the incompatibility is produced.

Also, make sure to purge any caching you have, on the WordPress installation and on the server level(Varnish, Redis, etc.).

If this does not help, I'll need to take a copy of your website for further analysis, and a clear example that shows the issue:
- Go to term archive hidden link
- Check field xxx.
- I expect to not see the value yyy, as it does not belong to any posts assigned to the term.
https://toolset.com/faq/provide-supporters-copy-site/

#1687391

Hi,
I did this with no success.
To reproduce the issue, please :
- Go to term archive hidden link
- Check the list of "Formations" at the end of the page, where you'll see the parent "Etablissement" in bold;
- You'll see there is only 2 Etablissements : IST and SOM;
- Then go back at the top of the page, in filters section, and check the "Etablissement" filter, where you'll see all Etablissements, instead of displaying only those that actually have Formations.
Thank you.

#1687587

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Thank you, I understand the issue better now.

You are trying to filter the archive results with a relationship("etablissement"), and taxonomies ("niveau" and "type de formation"). Let me investigate these issues and get back to you.

#1689969

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I tried to reproduce the issue on a clean install by creating an archive view with a filter on a relationship and a filter on the taxonomy. Filter values contained only the values of the returned results.

I'll need to investigate this further and for that, I would like to take a copy of your website. We prefer Duplicator, but it sometimes fails when Wordfence is active. https://toolset.com/faq/provide-supporters-copy-site/
Can you take a Duplicator copy, and make sure to use filters to reduce the size of the copy. hidden link
If Duplicator fails to create a copy, we'll need a database copy/export, plugins, and theme folders, all in a zip file.
Your next reply will be private to let you share the download link safely.

#1691579

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I was not able to narrow down this issue. The issue was still reproduced in a minimal setup(Default theme+only toolset plugins).

I tried a new archive for the "Domaines" taxonomy, and added the minimal filters to it and the issue was still reproduced.

Let me approach our 2nd Tier for assistance on this and get back to you as soon as possible.

#1697759

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Roman,

Our 2nd Tier has worked on this issue and we think that the archive template is full of all kinds of stuff that makes it difficult to see what’s actually going on, very many conditional shortcodes etc., so we deleted them all to just have a clear view of the search filters and the archive results. It looks like it works. Check this screen recording: hidden link

When we first load the archive the options available in the filters are all valid. Now note that we choose one option from one of the filters. The results update and both of the other filters update to remove invalid filter options, just as expected.

Currently, you are re-using the same custom archive for many different archives and then you add a lot of conditionals to display different things depending on which archive is being displayed.
We would suggest that it is probably safer to just make individual archives rather than shoe-horning them all into one. You can always make a content template, to use for designing the output loop, that is the same across the archives to minimize the work.

It is a particularly bad idea to use the conditional shortcodes within the loop output, as it means they are repeated for every result and can be costly.

Would you like to try creating an archive template only for the "Domaines" taxonomy and put on it only the filters that you will be using(relationship, and the other 2 taxonomies)?

#1706459

Hello and thank you,
I've just tested this with a way simpler view, and get the same wrong results.
Please see hidden link, which is a term archive page, where you may see all "Classement 2019" choices are available. But if you select the first one, "Très bonne qualité", you'll see no result...
Those choices should have been deactivated, as per the settings I checked in this brand new view : hidden link
Thank you.

#1707729

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Thank you for your feedback. And my apologies for the late reply.

I can see the issue in this view too. Let me approach our 2nd tier again for assistance. And I'll get back to you as soon as possible.

#1708541

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Our 2nd Tier was not able to reproduce the same issue. We built a similar archive on our local copy and the issue was not present on it.

So I tried it on your server too and I was not able to reproduce the issue. Check this screenshot hidden link
It is for this newly created archive template hidden link
Would you like to update this template markup to suit you and check if it will still present the issue?

#1708801

Hello and thank you,
I have copied the view and everything works fine until I add this code

[wpv-post-body view_template="infos-pour-etablissement"]

it breaks down the filter prefiltering.
Thank you.

#1709075

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I created another content template and added its code gradually. Finally, it seems that this shortcode is responsible for this issue:

[show_related_domaines2]

Once we remove it, the issue is not reproduced again.

The shortcode is defined in custom code in Toolset->Settings->Custom Code. It uses a view to render results separated by (,), then it splits the results by (,) and counts them.
Maybe if you build another shortcode that won't use a view can help fix this issue. Would you try that way?

#1709609

This code was from Luo Yang:
https://toolset.com/forums/topic/get-terms-from-children-posts/page/2/#post-1708563
It purpose was to get a list of most popular terms from children posts.
I'm not quite sure how it would be possible otherwise. My goal was to use Toolset as much as possible, but it seems there is some limitations here.
Could you please confirm what solution you would recommend ?
Thank you.

#1710155

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Let me approach our 2nd Tier for assistance and I'll get back to you as soon as possible.

#1714659

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and my apologies for the late reply.

We'll need to build another shortcode, similar to "show_related_domaines2", without using a Toolset view.

I came up with the following code, but I am not sure if it will work. I'll be discussing this with my colleague Luo and get back to you.


function count_etablissement_formation_domaines( $etablissement_id ) {

	// Formations related to etablissement
	$formations = toolset_get_related_posts( 
		// get posts related to this one
		$etablissement_id, 
	 
		// Relationship between the posts
		'formation-etablissement', 
	 
		// Additional arguments
		[
			'query_by_role' => 'child', 
			'limit' => -1, 
			'return' => 'post_id'
		]
	);

	$domaines = [];

	// foreach formation get taxonomy domaines terms.
	foreach ($formations as $formation) {
		$terms = wp_get_post_terms( $formation->ID, 'domaines', array( 'fields' => 'ids' ) );
		$domaines = array_merge( $domaines, $terms );
	}
	// get unique domaines.
	$domaines = array_unique($domaines);
	
	return count( $domaines );
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.