Skip Navigation

[Resolved] [Bug report with fix] Taxonomy filters not working on taxonomy archive pages

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

Problem:

Taxonomy filter of normal post view does not work as expected in the taxonomy archive page.

Solution:

This is fixed in Views 2.7.3, you can download it here:
https://toolset.com/account/downloads/

Relevant Documentation:

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
- 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/Hong_Kong (GMT+08:00)

This topic contains 22 replies, has 3 voices.

Last updated by Francesco 5 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#923614
views-bug-taxonomy-filter.png
views-bug-taxonomy-filter-expected.png

I am trying to use a taxonomy filter as follows:

[wpv-control-post-taxonomy taxonomy="tipologia-annuncio" type="select" url_param="wpv-tipologia-annuncio"]

Link to a page where the issue can be seen:
hidden link
Note: I have now fixed the bug by modifying the plugin (see below) so the bug is currently not visible on the page, but you can see it on the attached screenshot.

I expected to see:
All the taxonomy terms listed in the filter (see attached screenshot)

Instead, I got:
Only the term of the current (queried term) taxonomy archive. See attached screenshot.

Following the fix to be applied on file wp-views/embedded/inc/walkers/wpv_walker_taxonomy_select.class.php around line 127.

Original code:

		// If the current page is a taxonomy page for the taxonomy the filter refers to
        if ( $this->in_this_tax_archive_page ) {
		    // ... and if the queried taxonomy term is the current term rendered in the filter
            if ( $this->tax_archive_term->slug == $taxonomy_term->slug ) {
                // ... display the term and make it selected
				if ( $this->walker_args['counters'] ) {
					$wpv_tax_criteria_matching_posts = array();
					$wpv_tax_criteria_to_filter = array( $taxonomy_term->term_id => $taxonomy_term->term_id );
					$wpv_tax_criteria_matching_posts = wp_list_filter( $this->walker_args['query_cache'], $wpv_tax_criteria_to_filter );
					$taxonomy_term->tax_option = str_replace( '%%COUNT%%', count( $wpv_tax_criteria_matching_posts ), $taxonomy_term->tax_option );
				}
                $output .= '<option value="' . $tax_value . '" selected="selected">' . $indent . $taxonomy_term->tax_option . "</option>\n";
            }
            // ... else disregard this taxonomy term option for the filter
        } else {

Fixed code:

		// If the current page is a taxonomy page for the taxonomy the filter refers to
	    // ... and if the queried taxonomy term is the current term rendered in the filter
        if ( $this->in_this_tax_archive_page && $this->tax_archive_term->slug == $taxonomy_term->slug ) {
			// ... display the term and make it selected
			if ( $this->walker_args['counters'] ) {
				$wpv_tax_criteria_matching_posts = array();
				$wpv_tax_criteria_to_filter = array( $taxonomy_term->term_id => $taxonomy_term->term_id );
				$wpv_tax_criteria_matching_posts = wp_list_filter( $this->walker_args['query_cache'], $wpv_tax_criteria_to_filter );
				$taxonomy_term->tax_option = str_replace( '%%COUNT%%', count( $wpv_tax_criteria_matching_posts ), $taxonomy_term->tax_option );
			}
			$output .= '<option value="' . $tax_value . '" selected="selected">' . $indent . $taxonomy_term->tax_option . "</option>\n";
            // ... else disregard this taxonomy term option for the filter
        } else {		
#924030

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - As I understand, you have taxonomy archive for custom taxonomy XYZ and you want to filter same taxonomy archive with the terms of XYZ taxonnomy - correct? If Yes:

This is not possible as you can display only posts belongs to the current term which you are displaying.

For example, post A belongs to term 1, post B belongs to term 2, and you are on archive page that displays the term 1.

you can not display Post B in the archive page of term 1. so we can not filter taxonomy archive with same taxonomy.

you can't filter a taxonomy archive by the same taxonomy. WordPress Archives are not designed to work for a single term within a taxonomy.

If this is not the case, please let me know, I would like to debug this further.

#924041

Hi Minesh,
unfortunately, you did not understand correctly the request. I am talking about the available choices in the drop-down taxonomy filter, not about the posts displayed in the page.
That filter is displayed sitewide and it should always have all the available options so that a user can perform any search from any page (including taxonomy archive pages). Of course when a search is performed the results will be displayed on a different page. Unfortunately, the filter doesn't behave correctly on taxonomy pages.
Please check the attached screenshots, I believe they're pretty clear.
There's a bug in the code and I have a posted a fix. Please forward it to your dev team.
Thank you.

#924045

Minesh
Supporter

Languages: English (English )

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

Well - I understand. I need to check first on your install how you setup the archive. Then I will consult our Devs with all information.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#924598

Minesh
Supporter

Languages: English (English )

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

Well - I consult our Devs and they confirmed that its not a bug. Simply, you should not filter taxonomy archive which belongs to same taxonomy term. It's basically not supported.

I do not know if you know that you can build archives using custom search but only for post type archives. If you will have a taxonomy archive and you will try to filter the taxonomy archive with same taxonomy - you will see the following notice - please check screenshot:
=> hidden link

Even its also documented here:
=> https://toolset.com/documentation/user-guides/front-page-filters/#custom-search-archive

You can set-up a custom search for any ‘post’ type including ‘pages’, ‘posts’ and all custom post types (but not for users and taxonomy).

You should have a another page - instead of archive, where you should add the view you've added.

#948741

Unfortunately, it seems you still haven't understood the real problem here, so I will try to explain it from a different perspective. Please forget temporarily all that we have discussed until now and imagine the following scenario:

I want a custom search widget that allows the visitor to search (custom) posts by category/taxonomy. The search widget is included in a widget area that is displayed on EVERY page of the website. Of course, the custom search view and the widget are built according to the documentation that you also linked in your last message.
In this scenario, the search form in the widget is INCORRECT when it's displayed in the taxonomy term archive pages, as it doesn't show all the available categories in the form. Please note that I am talking about the form, NOT about the displayed posts! That way the user cannot perform some searches from those pages. This is definitely a bug in my opinion.

I have also recorded a short video that explains in detail the issue, reproduced in a vanilla WordPress install:
hidden link

If you still think this is not a bug (which would be absurd in my opinion), I would really appreciate it if you could provide a filter to disable this odd behavior programmatically, so that I can fix it without being forced to hack the source code of the Views plugin.

Thank you.

#949054

Hello,

Minesh isn't available, I will take care of this thread.

I assume we are talking about the view "Ricerca annuncio":
hidden link
in section "Custom Search Settings", you are using option "Always show all values for inputs", so it should be able to output all the taxonomy terms listed in the filter. if it can not, then it should be a bug.

please provide a database dump file (ZIP file) of your website in below "private detail box", I need to duplicate same problem and debug it in my localhost, thanks.

#949071

Thanks for the details, I can download the file, will update this thread when there is anything found.

#950052

I can duplicate the same problem, and have escalated this thread, will update here if there is anything news.

#950081

Our 2nd tier supporter has confirmed it , and it is in the bug list of Views plugin now, our developers will take care of it.

#950105

Hi Luo Yang,
thanks for the update. Looking forward to getting the next fixed version.
Please, could you update this thread when the bugfix will be released?
Do you have any ETA?
Thank you.

#950112

There isn't any ETA, but since it is a bug, it will be fixed soon, maybe next version of Views plugin, as I mentioned above, I will update this thread if there is anything news.

#1099568

Hi there,
do you have any update regarding this bugfix?
Thank you.

#1099773

It is still in our to-do list in "Submitted" state, here is the comment from our developers:

we do not support filtering the the object defining the current archive. This means that on a taxonomy archive the filters by terms in that taxonomy are not applied.

So currently, I suggest don't use the same taxonomy filters in the taxonomy archive page.

#1100376

Hi Luo Yang,
thanks for your reply. Please note that on July 18th you wrote: "since it is a bug, it will be fixed soon". In the meantime, 1.5 months are passed and no updates on this.

Please also note that I have provided a bugfix for this issue (see the first message), so it would be just a matter of changing a couple of lines of code.

As I have already explained throughout the discussion on the thread, the problem is related to a search filter that is displayed sitewide, so there's not an easy way to avoid using on specific pages (like taxonomy archives), and by the way, it wouldn't be the desired result.

In other words, the suggestion included in your latest reply is not applicable.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.