Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple taxonomy options to the query block #44041

Closed
sb726 opened this issue Sep 10, 2022 · 16 comments
Closed

Add multiple taxonomy options to the query block #44041

sb726 opened this issue Sep 10, 2022 · 16 comments
Labels
[Block] Query Loop Affects the Query Loop Block Needs Design Feedback Needs general design feedback. Needs Technical Feedback Needs testing from a developer perspective.

Comments

@sb726
Copy link

sb726 commented Sep 10, 2022

Description

After upgrading from 6.0.1 to 6.0.2 the filtering functionality within the query loop on the editor stopped working when trying to filter category pages according to a custom taxonomy

Step-by-step reproduction instructions

Using a child theme of Blockbase the following worked with version 6.0.1 but not version 6.0.2

  1. Create a custom taxonomy using advanced custom fields (e.g. A, B, C)

  2. Create one or more categories (e.g. 1, 2, 3)

  3. Create several posts with a mix of different categories and identifiers from the custom taxonomy (e.g., 1A, 1B, 2A, 2C...)

  4. Use a category template and within the template editor create several different query loop blocks to display different parts of the taxonomy, e.g., one query loop for A types, one for B types etc

  5. For example, in the first query loop block, within the editor click off "inherit query from template" in settings to reveal filters. Identify the taxonomy created above and filter to A. Click back on "inherit query from template"

  6. Repeat for the second query loop block. Now choose B from within the taxonomy.

Expected behaviour (which worked in 6.0.1):

When clicking on a category link to be taken to the category page (from the template just created) clicking on category 1 would reveal only category 1 A types in the first query loop block, only category 1 B types in the second and so on.

Moving to a category 2 page the A and B blocks changed to category 2 posts

After updating to 6.0.2 the filtering did not work. All query loop blocks showed all posts and there is no filtering by taxonomy. Clicking off "inherit query from template" solved the taxonomy problem. However, categories do not then work as expected.

Rolling back to 6.0.1 the filtering worked again.

I noted that 6.0.2 made some (unrelated?) changes to the query loop block and its filters.

Screenshots, screen recording, code snippet

No response

Environment info

6.0.2

Blockbase child theme

Mac 16 (2019)

Safari 15.6.1

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

@carolinan carolinan added [Block] Query Loop Affects the Query Loop Block Needs Testing Needs further testing to be confirmed. labels Sep 12, 2022
@carolinan
Copy link
Contributor

Hi, are you able to you provide testing instructions that does not involve third party plugins (ACF)?.

@sb726
Copy link
Author

sb726 commented Sep 12, 2022 via email

@sb726
Copy link
Author

sb726 commented Sep 14, 2022 via email

@carolinan
Copy link
Contributor

No. You can enable notifications / subscribe to be notified when there are any replies to this issue.

@ndiego
Copy link
Member

ndiego commented Sep 27, 2022

After a bit of investigation, there were a handful of Query Loop changes made in 6.0.2 here: https://github.com/WordPress/gutenberg/commits/wp/6.0.

@gziolo @draganescu would you guys have any insight into this issue?

@draganescu
Copy link
Contributor

To do this you have to remove the “inherit query from template” option, set your filters, then reapply “inherit query…”

Howdy @sb726 I think this is the bit that changed. You were using a weird behavior which more recent versions of the query block attempt to fix: once you set inherit query it will only use the global query on that page, so all settings get ignored.

@sb726
Copy link
Author

sb726 commented Sep 28, 2022

Many thanks @draganescu @ndiego for this reply. This was actually my concern.

The "weird behaviour" was actually very useful. It allowed you to use a global query (e.g. a category query) but to then filter this according to whatever custom taxonomy you happened to be using. In principle, to be able to organise a category page, index page etc. according to other custom taxonomies or even tags seems like a pretty standard thing to do.

It enables you, for example, to cross filter a category page and have different blocks for different parts of any custom taxonomy -- really useful.

Is there now any way to achieve this same filtering directly within the query block or is it necessary to write custom PHP queries?

I hope that makes sense. Even more, I hope the filtering functionality will be reintroduced in to the query block but perhaps in a more obvious way allowing for global queries but with added filtering for taxonomies, tags etc.

@draganescu
Copy link
Contributor

@sb726 this sounds interesting. Could you please offer a concrete example of:

cross filter a category page and have different blocks for different parts of any custom taxonomy

I am not sure I understand what this means in practice.

I hope the filtering functionality will be reintroduced

Since query blocks are self contained in terms of their settings, what is wrong with using one query block that follows the global query and another one with a custom query in the same page?

@muhammadharoonbro
Copy link

Please add filter by custom field in the Query Loop block.
I'm trying to use Query loop and filter all posts (students) who have English field in a custom field.

@Thelmachido Thelmachido added [Type] Bug An existing feature does not function as intended and removed Needs Testing Needs further testing to be confirmed. labels Sep 29, 2022
@draganescu draganescu added Needs Design Feedback Needs general design feedback. Needs Technical Feedback Needs testing from a developer perspective. and removed [Type] Bug An existing feature does not function as intended labels Sep 29, 2022
@ntsekouras
Copy link
Contributor

To do this you have to remove the “inherit query from template” option, set your filters, then reapply “inherit query…”

Howdy @sb726 I think this is the bit that changed. You were using a weird behavior which more recent versions of the query block attempt to fix: once you set inherit query it will only use the global query on that page, so all settings get ignored.

Without digging deep, I think that the difference you're describing and I agree with what @draganescu says. That was a bug where we retained some query attributes even if we had set to inherit, and even if it served your use case, unfortunately it was wrong implementation. It would be too confusing to have a setting to inherit but also have filters.

Having said that, I understand that folks have different use cases, and in 6.1 it will be easier to extend Query Loop in some ways. The documentation will be enhanced really soon, but the first PR got merged, that provides more info about that.

I hope that's helpful to @sb726 and @muhammadharoonbro for asking about the custom field.

@draganescu
Copy link
Contributor

Cool! I was not even aware of the cool extensibility options (via variations) that are upcoming and so well documented now. @sb726 do you think we can close this now?

@sb726
Copy link
Author

sb726 commented Sep 29, 2022

@draganescu

(I have tried to upload screenshots but for some reason this is not currently working so please see descriptions)

I hope this makes the use case clear. This refers to a category template.

First you have to switch off inherit query from template (see below)

[image not loading: In the editor go to a category template with a query block. Click on the query block and view settings. Click off "inherit query from template"]

Next, with the filtering options revealed, you can filter custom taxonomies etc.

[image not loading: In the settings panel that is revealed after step one above you have options to set the post type, order posts, filter categories, tags and custom taxonomies. As a use case, set the custom taxonomy to taxonomy 1]

Finally switch "inherit query from template" back on. The query block will reflect the relevant category from the category global query but it will also filter for the custom taxonomy. This works in 6.01 but not 6.02

Since query blocks are self contained in terms of their settings, what is wrong with using one query block that follows the global query and another one with a custom query in the same page?

The problem with this is that in my use case and I guess that of many others the custom taxonomy cuts across the category. In effect, the custom taxonomy is a subset of the category.

If I allow a block with the global query I get posts from a single category but every custom taxonomy. This completely destroys the functionality. If I instead use a custom query (in 6.02) I get the correct custom taxonomy but again for every category. Again this destroys the functionality.

In effect I wish to execute a SQL query for a single query block along the lines of (bearing in mind that the global query is on a category template):

SELECT * FROM POSTS

WHERE CATEGORY = CATEGORY 1
AND CUSTOM TAXONOMY = CUSTOM TAXONOMY 1
OR CUSTOM TAXONOMY = CUSTOM TAXONOMY 2

Different blocks would reference different custom taxonomy terms.

This query was possible in the query block in 6.01. It does not seem to be possible in 6.02.

I sense that @ntsekouras understands the issue and has determined that the behaviour I was using is a bug. However, I am not clear from the response whether the functionality I describe will be reintroduced into the latest version of wordpress.

Just to be clear. I do not think this is particularly weird behaviour nor a minor use case. Being able to filter the global query for a category etc. according to custom taxonomies and tags seems like a pretty basic and fundamental thing you might want to do for a wide range of websites.

I need to read the linked article in more depth to understand what extensions may have been made to the query loop but in short, if the above SQL query is not possible within the current query loop it would be really useful to introduce this functionality or explain how it can be achieved.

@muhammadharoonbro
Copy link

To do this you have to remove the “inherit query from template” option, set your filters, then reapply “inherit query…”

Howdy @sb726 I think this is the bit that changed. You were using a weird behavior which more recent versions of the query block attempt to fix: once you set inherit query it will only use the global query on that page, so all settings get ignored.

Without digging deep, I think that the difference you're describing and I agree with what @draganescu says. That was a bug where we retained some query attributes even if we had set to inherit, and even if it served your use case, unfortunately it was wrong implementation. It would be too confusing to have a setting to inherit but also have filters.

Having said that, I understand that folks have different use cases, and in 6.1 it will be easier to extend Query Loop in some ways. The documentation will be enhanced really soon, but the first PR got merged, that provides more info about that.

I hope that's helpful to @sb726 and @muhammadharoonbro for asking about the custom field.

No. I am not able to fetch results with same custom field value in post_meta table. Please tell me in details because Query loop block have no such option to do so.

@ntsekouras
Copy link
Contributor

I sense that @ntsekouras understands the issue and has determined that the behaviour I was using is a bug. However, I am not clear from the response whether the functionality I describe will be reintroduced into the latest version of wordpress.

@sb726 if I understand correctly, your use case is not a standard query, as there is not a template in the hierarchy that supports multiple taxonomies/terms at once. It could be fixed by adding tax_relation in Query Loop and then you could have a page with a non inherit Query Loop. Right now the relation is AND. This is part of #24934.

No. I am not able to fetch results with same custom field value in post_meta table. Please tell me in details because Query loop block have no such option to do so.

@muhammadharoonbro there is no filter for post meta in Query Loop inspector controls and there will not be one for various reason, like because there is no support for post meta in REST API. This is what the docs will try to help with, but in general a really customized extended Query Loop also needs PHP handling for modifying the query, the REST API etc..

@draganescu
Copy link
Contributor

However, I am not clear from the response whether the functionality I describe will be reintroduced into the latest version of wordpress.

Thanks for the well documented explanation @sb726 🙇🏻 Juts wanted to make sure this is visible: the answer to the above is in the comment from @ntsekouras

It could be fixed by adding tax_relation in Query Loop and then you could have a page with a non inherit Query Loop. Right now the relation is AND. This is part of #24934.

@draganescu draganescu changed the title There is a problem with the query loop filtering functionality Add multiple taxonomy options to the query block Oct 3, 2022
@sb726
Copy link
Author

sb726 commented Oct 3, 2022

@ntsekouras I think my use case might be "reasonably" standard. Take a category page (which could be issues of a magazine, pages of a clothes catalogue, types of books etc.) and divide that category page up according to some custom taxonomy. You need the inherit query property so that the right category page appears when clicking on a category link. But you might also need to further filter or subdivide those categories. That you could do this in 6.01 was very useful.

I do not fully understand the tax_relation point but I see that #24934 may address the points I am raising. Just to be clear: so long as you can use inherit Query Loop AND add a custom taxonomy (which I think is what the tax_relation point refers to) then my point is addressed.

Anyway I think this is probably all that can be said. I understand that these points are being taken on in the workflow elsewhere so I am happy @draganescu to close this discussion now if need be. Thanks for changing the title which I think now better addresses the issues being raised. I look forward to the new updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block Needs Design Feedback Needs general design feedback. Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

No branches or pull requests

7 participants