Skip to content

Fix post exclusion when post__in is set via Advanced Query Loop#8

Merged
roborourke merged 8 commits intomainfrom
claude/fix-issue-7-query-loop-MZH8c
Jan 27, 2026
Merged

Fix post exclusion when post__in is set via Advanced Query Loop#8
roborourke merged 8 commits intomainfrom
claude/fix-issue-7-query-loop-MZH8c

Conversation

@roborourke
Copy link
Collaborator

Summary

This PR fixes a bug where the "Exclude Displayed Posts" feature didn't work correctly when a query loop used the post__in parameter (commonly set by the Advanced Query Loop plugin). WordPress ignores post__not_in when post__in is present, so we now filter the post__in array directly to exclude already-displayed posts.

Key Changes

  • New exclude_posts_from_query() function: Handles exclusions intelligently by:

    • Filtering out excluded IDs from post__in when it's set (since it takes precedence)
    • Also setting post__not_in for queries without post__in
    • Merging with any existing exclusions to avoid duplicates
  • Refactored exclusion logic: Updated both excludeDisplayed and excludeDisplayedForCurrentLoop code paths to use the new helper function, eliminating code duplication

  • Added comprehensive E2E tests: Two new test cases verify:

    • Exclude displayed posts works correctly with Advanced Query Loop's post__in parameter
    • Multiple post templates with exclusions don't show duplicate posts
  • Updated dev environment: Added Advanced Query Loop plugin to .wp-env.json for testing

Implementation Details

The fix addresses a WordPress core behavior where post__in takes precedence over post__not_in. When Advanced Query Loop sets specific post IDs via post__in, our exclusion logic now:

  1. Removes excluded post IDs from the post__in array
  2. Still sets post__not_in for fallback behavior in other query scenarios
  3. Properly handles edge cases like non-array values and merges with existing exclusions

When a query loop uses post__in (e.g., via Advanced Query Loop plugin),
WordPress ignores post__not_in. This fix ensures exclusions work correctly
by also filtering the post__in array to remove already displayed post IDs.

- Add exclude_posts_from_query() helper that handles both post__not_in and post__in
- Refactor modify_query_from_block_attrs() to use the new helper
- Add Advanced Query Loop plugin to test environment
- Add E2E test for post__in exclusion behavior

Fixes #7

https://claude.ai/code/session_01GpFyKZGFSn2rTG4WmkumeU
@roborourke roborourke changed the title Fix post exclusion when post__in is set via Advanced Query Loop Fix post exclusion when post__in is set via Advanced Query Loop Jan 23, 2026
@github-actions
Copy link

github-actions bot commented Jan 23, 2026

Playwright test results

passed  10 passed

Details

stats  10 tests across 3 suites
duration  30.3 seconds
commit  c0b0233

@roborourke roborourke merged commit 4a4665e into main Jan 27, 2026
1 check passed
@roborourke roborourke deleted the claude/fix-issue-7-query-loop-MZH8c branch January 27, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants