Fix: Post ID ordering not working on frontend#151
Open
ryanwelcher wants to merge 4 commits intotrunkfrom
Open
Conversation
Fixes #148 ## Problem When "Post Order By" is set to "Post ID" in the AQL block, posts display in correct order in the editor but fall back to date ordering on the frontend. Query Monitor confirms WP_Query uses `ORDER BY post_date` instead of `ORDER BY ID`. ## Root Cause - UI passes lowercase 'id' value to backend - REST API (editor) automatically normalizes 'id' → 'ID' - WP_Query (frontend) is case-sensitive and requires uppercase 'ID' - Unrecognized lowercase 'id' causes fallback to default date ordering ## Solution Created OrderBy trait that normalizes the orderBy parameter: - Accepts lowercase 'id' from block attributes - Converts to uppercase 'ID' for WP_Query compatibility - Ensures consistent behavior across editor and frontend ## Changes - Add `includes/Traits/OrderBy.php` with normalization logic - Update `Query_Params_Generator.php` to use OrderBy trait - Update `query-loop.php` to process orderBy parameter - Add comprehensive e2e tests (6 tests, 100% passing) - Add test documentation and blueprint setup - Update CLAUDE.md with architecture notes ## Testing E2e tests verify: - UI control displays Post ID option - Block attributes set correctly - Editor preview orders by ID - Frontend orders by ID (not date) - Ascending and descending order work - Switching between order types works Tests confirmed: - ✅ 6/6 pass with fix - ❌ 2/6 fail without fix (reproduces bug)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #148
Problem
When "Post Order By" is set to "Post ID" in the AQL block, posts display in correct order in the editor but fall back to date ordering on the frontend. Query Monitor confirms WP_Query uses
ORDER BY post_dateinstead ofORDER BY ID.Root Cause
Solution
Created OrderBy trait that normalizes the orderBy parameter:
Changes
includes/Traits/OrderBy.phpwith normalization logicQuery_Params_Generator.phpto use OrderBy traitquery-loop.phpto process orderBy parameterTesting
E2e tests verify:
Tests confirmed: