64250 redirect guess 404 permalink#10975
Conversation
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Weston Ruter <[email protected]>
Co-authored-by: Mukesh Panchal <[email protected]>
… control This commit introduces the `search_position` parameter to the `WP_Query` class, allowing developers to specify search behavior for posts: finding terms at the start, end, or anywhere within fields. Corresponding functionality in `canonical.php` has also been updated, and comprehensive unit tests were added to ensure reliability of the new behavior.
| * @type int $day Day of the month. Default empty. Accepts numbers 1-31. | ||
| * @type bool $exact Whether to search by exact keyword. Default false. | ||
| * Cannot be used together with `$search_position`. | ||
| * @type bool $search_position Whether to search start, ends or is anywhere within keyword. Default anywhere. |
There was a problem hiding this comment.
| * @type bool $search_position Whether to search start, ends or is anywhere within keyword. Default anywhere. | |
| * @type string $search_position Whether to search start, ends or is anywhere within keyword. May be 'start', 'end', or the default 'anywhere'. |
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
I've added a few notes inline.
| $query_vars = &$this->query_vars; | ||
| $this->query_vars_changed = true; | ||
|
|
||
| if ( ! empty( $query_vars['exact'] ) && ! empty( $query_vars['search_position'] ) ) { |
There was a problem hiding this comment.
- Let's allow a dev to pass both
exact => true, search_position => anywherewithout throwing a notice, as it's the documented default. - Add
search_position => ''tofill_query_vars()method.
| * | ||
| * @ticket 64250 | ||
| * | ||
| * @dataProvider data_search_position_values |
There was a problem hiding this comment.
Per unit testing docs for providers used for a single test
| * @dataProvider data_search_position_values | |
| * @dataProvider data_search_position_with_different_values |
| * | ||
| * @return array | ||
| */ | ||
| public function data_search_position_values() { |
There was a problem hiding this comment.
As above.
| public function data_search_position_values() { | |
| public function test_search_position_with_different_values() { |
| array( | ||
| 'post_status' => 'publish', | ||
| 'post_title' => 'alpha beta gamma', | ||
| 'post_content' => 'delta epsilon zeta', |
There was a problem hiding this comment.
Can you add the content to the shared fixture and remove the need for creating the post here? If so, it would speed up the tests slightly.
| * | ||
| * @ticket 64250 | ||
| */ | ||
| public function test_search_position_with_invalid_value() { |
There was a problem hiding this comment.
A data provider with a variety of types would be helpful to ensure nothing errors:
You'll need to fix the coding standareds for alignment
array(
'null' => array( null ),
'true' => array( true ),
'false' => array( false ),
'int' => array( 123 ),
'float' => array( 123.456 ),
'string' => array( 'test' ),
'empty' => array( '' ),
'zero' => array( 0 ),
'negative' => array( -1 ),
'array' => array( array( 'test' ) ),
'empty array' => array( array() ),
);
| * @since 5.3.0 Introduced the `$meta_type_key` parameter. | ||
| * @since 6.1.0 Introduced the `$update_menu_item_cache` parameter. | ||
| * @since 6.2.0 Introduced the `$search_columns` parameter. | ||
| * @since 7.0.0 Introduced the `$starts_with` parameter. |
There was a problem hiding this comment.
| * @since 7.0.0 Introduced the `$starts_with` parameter. | |
| * @since 7.0.0 Introduced the `$search_position` parameter. |
There was a problem hiding this comment.
In this file there are a few tests to ensure the default colums are used for empty/invalid search_columns values. Add assertions to ensure that the slug is not included in those tests.
Trac ticket: https://core.trac.wordpress.org/ticket/64250
Use of AI Tools
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.