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

Query block taxonomy filter does not work on frontend if taxonomy is not set to publicly_queryable #59257

Closed
eric-michel opened this issue Feb 21, 2024 · 2 comments · Fixed by #59458
Assignees
Labels
[Block] Query Loop Affects the Query Loop Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@eric-michel
Copy link

eric-michel commented Feb 21, 2024

Description

When publicly_queryable is set to false for a custom taxonomy, it can still be selected in the query block filter criteria (and filters properly in the editor) but does not properly filter on the frontend.

Ideally, filtering would remain working even when a taxonomy is set to not be publicly_queryable.

Step-by-step reproduction instructions

  1. Register a custom taxonomy with publicly_queryable set to false, and apply it to a post type.
  2. Add some terms to the taxonomy.
  3. Create some sample posts with a variety of terms selected.
  4. Add a query block to a test page and filter for one of the terms used in your sample posts.

You should notice the list of posts properly filtered in the editor, but once you save the page and view it on the frontend, all posts will appear.

This issue is also described in this comment from over a year ago: #41067 (comment)

Screenshots, screen recording, code snippet

No response

Environment info

  • WP version 6.4.3
  • Twenty Twenty-Four theme
  • Gutenberg plugin 17.7.0

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

Yes

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

Yes

@eric-michel eric-michel added the [Type] Bug An existing feature does not function as intended label Feb 21, 2024
@jordesign jordesign added [Block] Query Loop Affects the Query Loop Block Needs Testing Needs further testing to be confirmed. labels Feb 21, 2024
@t-hamano
Copy link
Contributor

Thanks for the report.

From my understanding, the fact that a taxonomy with publicly_queryable set to false can be selected on the editor side seems to be a bug in itself.

For example, the blocks below filter only taxonomies for which publicly_queryable is true.

Next post / Previous post:

https://github.com/WordPress/gutenberg/blob/9a8984afb45df1635b2a5048b33e8ab9f95bff27/packages/block-library/src/post-navigation-link/edit.js#L79-L86

Post Terms:

https://github.com/WordPress/gutenberg/blob/9a8984afb45df1635b2a5048b33e8ab9f95bff27/packages/block-library/src/post-terms/edit.js#L50-L58

On the other hand, the Query Loop block does not take publicly_queryable into account:

https://github.com/WordPress/gutenberg/blob/9a8984afb45df1635b2a5048b33e8ab9f95bff27/packages/block-library/src/query/utils.js#L130-L144

@t-hamano t-hamano removed the Needs Testing Needs further testing to be confirmed. label Feb 22, 2024
@eric-michel
Copy link
Author

Thanks for the quick reply! I did consider that it might be a bug that non-publicly-queryable taxonomies would appear in the filter at all. However, I'm hoping this will be fixed such that they can be reliably used.

I think it makes sense for non-publicly-queryable taxonomies to be hidden from the Post Terms block (why publicly display terms that are not public?) but there are many applications in which I'd like to filter a query block based on an otherwise-hidden taxonomy. I'm actually dealing with that circumstance right now, which is how I discovered this issue.

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 [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants