Skip to content

Query Loop Block: Add support for matching all taxonomy terms in block filter#70548

Open
BugReportOnWeb wants to merge 9 commits intoWordPress:trunkfrom
BugReportOnWeb:feat/toggle-to-match-all-terms
Open

Query Loop Block: Add support for matching all taxonomy terms in block filter#70548
BugReportOnWeb wants to merge 9 commits intoWordPress:trunkfrom
BugReportOnWeb:feat/toggle-to-match-all-terms

Conversation

@BugReportOnWeb
Copy link
Copy Markdown
Contributor

What?

Closes #58714

This PR adds a new toggle option to the Query block settings to allow matching all selected taxonomy terms (AND relation) instead of the default any (OR relation).

Why?

Currently, the Query block uses an OR relation for filtering posts by multiple taxonomy terms, which returns posts matching any of the selected terms. Some use cases require a stricter filter that only returns posts matching all selected terms across one or more taxonomies. This PR introduces that capability with a UI toggle and ensures consistency between editor and frontend behavior.

How?

  • Added a matchAllTerms attribute to the Query block.
  • Rendered a ToggleControl in the block settings panel to toggle AND vs OR logic.
  • In the editor:
    • Applied client-side filtering on fetched posts when matchAllTerms is true.
  • On the frontend:
    • Modified tax_query parts to use operator: AND when matchAllTerms is enabled.
  • Updated default handling and ensured consistent fallback for core and custom taxonomies.

Testing Instructions

  1. Insert a Query Loop block and apply taxonomy filters.
  2. Select multiple terms for any taxonomy (e.g. categories)
  3. Toggle "Require all selected terms" in the block settings (Filters -> Taxonomies).
  4. Confirm the following:
    • When off (default): shows posts matching any selected terms.
    • When on: shows posts only if they match all selected terms.
  5. Verify the behavior in both the editor and on the frontend.

Screenshots or screencast

Screen.Recording.2025-06-27.at.10.50.10.PM.mov

@BugReportOnWeb BugReportOnWeb marked this pull request as ready for review June 27, 2025 18:19
@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @JoshuaLindquist.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: JoshuaLindquist.

Co-authored-by: BugReportOnWeb <devasheeshkaul@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Block] Query Loop Affects the Query Loop Block labels Jun 28, 2025
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 [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query Loop block: Display only content that matches all selected filters.

2 participants