Display post types on facets with duplicate labels. #2541
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
When two or more taxonomy facets are added with the same label, such as the core
category
("Category") taxonomy and the WooCommerceproduct_cat
(also "Category") taxonomy, they are not differentiated on the front end. This PR adds the labels for associated post types in parentheses to the headings of taxonomy facets whenever there are other facets with the same label. For example, if both the category taxonomies mentioned above are added they will be displayed as "Category (Posts)" and "Category (Products)", but if only one is present then the post type will be omitted.Alternate Designs
I experimented with displaying the post types as little badges next to the headings, like on search results, but it required a bit too much CSS and I was not confident that the appearance would be consistent across different themes.
Benefits
If a user adds taxonomy facets with ambiguous headings, they will automatically be differentiated.
Possible Drawbacks
In some cases the post type name may be ambiguous to end users and the site owner may not want to expose it to them. Arguably "Posts" falls into this category for sites that normally present these as "News" or "Articles". Long term a more robust user interface where users can enter any arbitrary heading they like for facets may be preferable.
Verification Process
Category (category)
facet. On the front end this facet should be labelled "Category".Category (product_cat)
facet. On the front end this should be labelled "Category (Products)" and the existingCategory (category)
facet should be labelled "Category (Posts)".Category (product_cat)
facet. On the front end the remainingCategory (product_cat)
facet should be labelled just "Category".For sites where one of these taxonomies is associated with multiple post types, the post types should all be listed, separated by comments. For example, if the
category
taxonomy is added to Pages then the label should be "Category (Posts, Pages)" when another category facet is present.Checklist:
Applicable Issues
Addresses #2497.
Changelog Entry
Adds post types to facet labels when needed to to differentiate facets with duplicate labels.