#57501 closed enhancement (fixed)
Backport the added query args to Pattern_Directory Controller
| Reported by: | ntsekouras | Owned by: | hellofromTonya |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.2 |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests gutenberg-merge has-test-info commit |
| Cc: | Focuses: |
Description
This ticket tracks the addition of 'per_page', 'page', 'offset', 'order', and 'orderby' args to WP_REST_Pattern_Directory_Controller
It's a backport from the Gutenberg plugin.(https://github.com/WordPress/gutenberg/pull/45293)
Change History (16)
This ticket was mentioned in PR #3861 on WordPress/wordpress-develop by @ntsekouras.
3 years ago
#1
- Keywords has-patch has-unit-tests added
@hellofromTonya commented on PR #3861:
3 years ago
#3
Once committed, I can open a PR in Gutenberg to synch the changes from here back to Gutenberg.
#4
@
3 years ago
- Keywords has-testing-info needs-testing added
The code in PR 3861 looks good. Updated a few areas for Core parity and a few tweaks for performance.
Next step: Needs a manual test to make sure it works as intended.
Copying testing instructions from the original Gutenberg PR:
## Testing Instructions 1. Ensure the remote patterns are still loading in the editor — the Featured query, the core patterns, and any theme-added patterns. Test the API endpoint in a REST client. 1. Try pagination, ex: `/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2` — It should show the middle 6 patterns on [wordpress.org/patterns/](https://wordpress.org/patterns/). 2. Try order: `/wp-json/wp/v2/pattern-directory/patterns/?category=37&per_page=3&orderby=date&order=asc` — should show the last 3 items on [wordpress.org/patterns/categories/footer/page/2/](https://wordpress.org/patterns/categories/footer/page/2/) 3. Make sure search still works `/wp-json/wp/v2/pattern-directory/patterns/?search=plants` — should match [wordpress.org/patterns/search/plants/](https://wordpress.org/patterns/search/plants/) 4. Make sure slug still works `/wp-json/wp/v2/pattern-directory/patterns/?slug=centered-text-title-with-two-columns` — should return a single pattern
This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.
3 years ago
#6
@
3 years ago
Using Postman and Application password generated from Dashboard.
- ✅
/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2shows items 7-12 from wordpress.org/patterns/- org screenshot: https://prnt.sc/wo7aNFafwGRB
- api screenshot: https://d.pr/i/OtvvXk
- ❌ returns these items: 43551 (Newsletter, Subscribe section design with title, description, background image and subscribe button), 44367 (Contact us/call action section design with gradient background and title, button), 44504 (footer section design with 3 column description, social media, contact and newsletter)
- Last page: https://prnt.sc/HioAL2jn-lNy
- 2nd last page: https://prnt.sc/zTMFHPfEL6I8
- ✅ Found fixed. only one item "Natural Hero Section"
- api screenshot: https://d.pr/i/ErVjz1
- ✅ Found single pattern titled "Centered text title with two columns"
#7
@
3 years ago
I have tested with Postman and Application password from WP Dashboard:
- ✅ I use
/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2
to show 7-12 items from https://wordpress.org/patterns/
Screenshot from ORG: https://prnt.sc/OJk3KNGldJNc
Screenshot from API: https://prnt.sc/xywwMcv9qRcZ
- ✅ Get the last three items (but in random order). 43551 (Newsletter, Subscribe section design with title, description, background image and subscribe button), 44504 (footer section design with 3 column description, social media, contact and newsletter), 44715 (Purchase, offerd, discount section with creative design) Screenshot from ORG (last page): https://prnt.sc/AiGT8D7l9rt- Screenshot from ORG (second last page): https://prnt.sc/6n31IWsMOyF-
- ✅ Get it fixed. Only one item was found "Natural Hero Section" Screenshot from API: https://prnt.sc/gNGQz-_z1lFV
- ✅ Get it fixed. Get only a single pattern title "Centered text title with two columns" Screenshot from API: https://prnt.sc/blB18Aw7U9fD
#8
@
3 years ago
Re trying.
- ✅ Found these 3 items:
- 43551 (Newsletter, Subscribe section design with title, description, background image and subscribe button)
- 44504 (footer section design with 3 column description, social media, contact and newsletter)
- 44715 (Purchase, offerd, discount section with creative design)
Last page: https://prnt.sc/HioAL2jn-lNy
2nd last page: https://prnt.sc/zTMFHPfEL6I8
I guess due to cache or something previous report was showing wrong.
Now seems working.
#9
@
3 years ago
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/3861
Environment
- Hardware: MacBook Pro Apple M1 Pro
- OS: macOS 12.6.2
- Browser: Safari 16.2
- Server: nginx/1.23.3
- PHP: 7.4.33
- WordPress: 6.2-alpha-54642-src
- Theme: twentytwentythree v1.0
- Gutenberg NOT activated
Actual Results
Manual UI Test
Ensure the remote patterns are still loading in the editor — the Featured query, the core patterns, and any theme-added patterns.
- ❌ While patterns are still loaded, there are both new and missing categories after the patch.
- ✅ For categories that matched between before/after the patch, the counts were the same.
Editor Patterns explorer counts before patch:
- Banners: 6
- Buttons: 3
- Columns: 5
- Featured: 16
- Footers: 9
- Gallery: 3
- Headers: 9
- Posts: 7
- Text: 9
After patch (🔴=missing, 🟡=new):
- 🔴 Banners: n/a
- Buttons: 3
- Columns: 5
- Featured: 16
- Footers: 9
- Gallery: 3
- Headers: 9
- 🔴 Posts: n/a
- 🟡 Query: 7
- Text: 9
- 🟡 Uncategorized: 3
Additional Notes
The user-facing WordPress.org Patterns directory has a different set of category filters from what is in core or in this backport PR. The directory currently includes:
- Buttons
- Columns
- Featured
- Footers
- Gallery
- Headers
- 🟡 Images
- Text
- 🟡 Wireframe
Items with 🟡 are not exposed in core or the PR. Additionally, these categories appear in core before/after the patch, but are not visible on the patterns site: Banners, Posts, Query, Uncategorized.
Supplemental Artifacts
| Patterns Explorer Before Patch | After Patch |
|---|---|
|
|
| WordPress.org Patterns Directory |
|---|
|
#10
@
3 years ago
Test Report
This is a follow-up to comment:9 with API test results. tl;dr: Found an issue when modifying search queries.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/3861
Environment
- Hardware: MacBook Pro Apple M1 Pro
- OS: macOS 12.6.2
- Application: Postman 10.8.3
- Server: nginx/1.23.3
- PHP: 7.4.33
- WordPress: 6.2-alpha-54642-src
Actual Results
API Test
Test the API endpoint in a REST client.
- ✅ Try pagination (
per_page, page, offset):
/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2Figure 1
/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=1&offset=6Figure 2
- ✅ Try order (
orderby, order):
/wp-json/wp/v2/pattern-directory/patterns/?category=26&per_page=5&orderby=date&order=ascFigure 3
- ❌ Make sure search still works (
search):
/wp-json/wp/v2/pattern-directory/patterns/?search=plantsFigure 4
🟢searchworks alone, and along with theper_pageandpageparameters.
🔴searchis not affected by theoffset,orderby, ororderparameters. Figure 5
- ✅ Make sure slug still works (
slug):
/wp-json/wp/v2/pattern-directory/patterns/?slug=centered-text-title-with-two-columnsFigure 6
- ✅ When setting parameters with invalid values (e.g.
per_page=200ororderby=foobar), the API responds with appropriate errors.
Additional Information
- These tests were performed with Postman and a rudimentary visualizer to compare retrieved results with those visible on the WordPress.org Patterns directory. See the image artifacts below for comparisons.
- Re: Test 2 -- The original test instructions included a sample category query for footers (37), but there appears to be a problem with the data which causes the test to fail. However, tests with other categories work as expected.
Supplemental Artifacts
Click an image to view the large version.
| Figure 1 | Figure 2 |
|---|---|
|
|
| Figure 3 | Figure 4 |
|
|
| Figure 5 | Figure 6 |
|
|
#11
@
3 years ago
Test Report
This is a follow-up to comment:9 regarding the reported failure during manual UI testing.
tl;dr: After the merge of [55098], this issue is resolved. Refreshing this ticket's PR against trunk would likewise resolve the categories displayed. Thank you, @ntsekouras, for pointing this out.
Patch tested: https://github.com/WordPress/wordpress-develop/pull/3861, plus PR 3854 which was merged after this ticket was created.
Actual Results
Manual UI Test
Ensure the remote patterns are still loading in the editor — the Featured query, the core patterns, and any theme-added patterns.
✅ Pattern categories displayed match those after applying the patch.
Supplemental Artifacts
| Patterns Explorer Before Patch | After Patch ✅ |
|---|---|
|
|
#12
@
3 years ago
- Keywords commit added; needs-testing removed
- Owner changed from to
- Status assigned → reviewing
Aha, [55098] was the missing part. Thanks @ironprogrammer @robinwpdeveloper @arrasel403 for the test reports! Well done!
Updating the keywords including marking for commit. Self-assigning for commit.
@hellofromTonya commented on PR #3861:
3 years ago
#14
Committed via https://core.trac.wordpress.org/changeset/55132.
#15
@
3 years ago
Follow-up: @ironprogrammer noted a problem with the API's use of `search` in conjunction with `offet`, `orderby`, and `order`.
In talking with @ryelle, the issue is replicated on the Pattern Directory API itself, meaning it's an issue on the API. It'll need to be fixed on wp.org, not within Core or Gutenberg.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)










Trac ticket: https://core.trac.wordpress.org/ticket/57501
Adds the 'per_page', 'page', 'offset', 'order', and 'orderby' args to WP_REST_Pattern_Directory_Controller.
GB PR: https://github.com/WordPress/gutenberg/pull/45293
--cc @hellofromtonya @ryelle