I use a nested Term Query. When a post is not assigned to any term the Query will display all terms registered with the Taxonomy.
This only happens when no Term of any Taxonomy is selected.
I have two taxonomies: Location and Genre (only these two are assigned to my CPT, nothing else)
The Term Query displays terms of the Location taxonomy. When I don’t select any Term of both available taxonomies the Query will display all terms of the Location taxonomy. As soon as I select a Term of the Genre taxonomy the Query works and will be empty.
Step-by-step reproduction instructions:
- Use a CPT and assign at least two custom taxonomies (TaxonomyA and TaxonomyB)
- Create a Term Query inside a Post Query that calls your CPT
- Set the nested Term Query to only include Post Terms of TaxonomyA
- Create a CPT without selecting any Term
- Your Term Query should now display all Terms registered with your TaxonomyA
- Now edit your post and select a Term of TaxonomyB
- The Term Query now is empty, as it should be
- WordPress version: latest
- Cwicly Plugin version: latest
Thank you for bringing this to our attention!
I have been able to reproduce this error on my end, and can confirm that all terms showing when no term has been selected is a bug.
Just to make sure we’re on the same page, is this how you have set up your Terms Query?
Thank you in advance, and apologies for the inconvenience.
thanks for getting back.
Yes, that’s how I set up the query
I just noticed that this issue also appears if I use a Term Query in a Single Post Template. So it seems it is the issue is not the nested query.
Reviewing the WordPress class, this looks like the intended behaviour when using the Terms query: WP_Term_Query::__construct() | Method | WordPress Developer Resources
Array or comma/space-separated string of term IDs to include.
Default empty array.
Would you be so kind as to confirm this before I move the thread to general.
unfortunately I don’t really understand these parameters so I can’t come to a conclusion myself just by looking at the developer resources.
If this indeed is intended behavior, would it be possible to modify the visibility conditions in a way to be able to hide the query in case the “default empty array” kicks in?
For example adding custom taxonomies to the visibility conditions so I could select: Show if > TaxonomyA > equal to > empty
Or something similar.
Because even if it is the default behavior it does not make it intuitive since it does not really make sense to display all terms when none are selected.
It makes sense in the context of a filter, in the sense that, you can show all results initially and allow a user to filter down those results by criteria.
I think it’s just two different models of thinking - one is starting with nothing and adding, and one is starting with everything and subtracting. There are valid use cases for both approaches.
To achieve what you want, you can potentially use a Visibility condition based on whether the url parameter of your filter is non-empty - that way you can hide the query if no filters have been selected. I haven’t tested this and it may cause the filters to not function if the Query is removed by the conditions, so needs to be tested.
ok, now I understand the logic behind this. Thanks for this explanation! In my case I don’t use any frontend filter though. I have a CPT where I want to display the Countries (Custom Taxonomy) that the post is assigned to. So when no country is selected the query should be empty.
As you can see in the screenshot of @Araminta I set up the query to include all Post Terms. That’s why I expect the query to be empty when no Post Terms are present.