Skip to content

Commit 381d113

Browse files
committed
Document and test paginated use
1 parent 960a796 commit 381d113

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ The `--synced-pattern` filter matches reusable block references by synced patter
8585
[--<field>=<value>]
8686
One or more args to pass to WP_Query.
8787

88+
Use native WP_Query pagination args like `--posts_per_page=<n>` and `--paged=<n>` to scan large sites in smaller batches. These args limit the candidate posts examined for a given run; they do not add pagination metadata to the command output.
89+
8890
[--field=<field>]
8991
Prints the value of a single field for each matching post.
9092

@@ -152,6 +154,9 @@ These fields are optionally available:
152154
# Limit the candidate posts scanned with a native query argument.
153155
$ wp block search --block=core/paragraph --showposts=50 --format=ids
154156

157+
# Scan the second batch of 100 candidate posts without changing output format.
158+
$ wp block search --block=core/paragraph --posts_per_page=100 --paged=2 --format=ids
159+
155160
# Restrict search to specific posts and return the match count.
156161
$ wp block search --style=rounded --post__in=21,42,84 --format=count
157162

‎features/block-search.feature‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,35 @@ Feature: Search posts by block usage
165165
[{"ID":{DOUBLE_QUOTE_POST_ID},"occurrences":2}]
166166
"""
167167

168+
Scenario: Search block usage with WP_Query pagination arguments
169+
Given a paged-first-post.html file:
170+
"""
171+
<!-- wp:quote --><blockquote class="wp-block-quote"><p>First paged match</p></blockquote><!-- /wp:quote -->
172+
"""
173+
When I run `wp post create paged-first-post.html --post_type=post --post_title='A Paged Match' --post_status=publish --porcelain`
174+
Then STDOUT should be a number
175+
And save STDOUT as {PAGED_FIRST_POST_ID}
176+
177+
Given a paged-second-post.html file:
178+
"""
179+
<!-- wp:quote --><blockquote class="wp-block-quote"><p>Second paged match</p></blockquote><!-- /wp:quote -->
180+
"""
181+
When I run `wp post create paged-second-post.html --post_type=post --post_title='B Paged Match' --post_status=publish --porcelain`
182+
Then STDOUT should be a number
183+
And save STDOUT as {PAGED_SECOND_POST_ID}
184+
185+
When I run `wp block search --block=core/quote --post_type=post --orderby=title --order=ASC --posts_per_page=1 --paged=1 --field=ID`
186+
Then STDOUT should be:
187+
"""
188+
{PAGED_FIRST_POST_ID}
189+
"""
190+
191+
When I run `wp block search --block=core/quote --post_type=post --orderby=title --order=ASC --posts_per_page=1 --paged=2 --field=ID`
192+
Then STDOUT should be:
193+
"""
194+
{PAGED_SECOND_POST_ID}
195+
"""
196+
168197
Scenario: Search blocks embedded from a specific pattern
169198
Given a pattern-rsvp-post.html file:
170199
"""

‎src/Block_Search_Command.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
* [--<field>=<value>]
3737
* : One or more args to pass to WP_Query.
3838
*
39+
* Use native WP_Query pagination args `--posts_per_page=<n>` and
40+
* `--paged=<n>` to scan large sites in smaller batches. These args limit the
41+
* candidate posts examined for a given run; they do not add pagination
42+
* metadata to the command output. Results in each page may not be equal and empty response isn't quarantee that next page won't have results.
43+
*
3944
* [--field=<field>]
4045
* : Prints the value of a single field for each matching post.
4146
*
@@ -109,6 +114,9 @@
109114
* # Limit the candidate posts scanned with a native query argument.
110115
* $ wp block search --block=core/paragraph --showposts=50 --format=ids
111116
*
117+
* # Scan the second batch of 1000 candidate posts without changing output format.
118+
* $ wp block search --block=core/paragraph --posts_per_page=1000 --paged=2 --format=ids
119+
*
112120
* # Restrict search to specific posts and return the count.
113121
* $ wp block search --style=rounded --post__in=21,42,84 --format=count
114122
*

0 commit comments

Comments
 (0)