Opened 6 years ago
Last modified 6 weeks ago
#51811 new enhancement
Query inconsistency between WP_Query and WP_Term_Query
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 4.6 |
| Component: | Query | Keywords: | good-first-bug has-patch has-unit-tests |
| Focuses: | coding-standards | Cc: |
Description
For the sake of standardization and simplicity would it be beneficial to use 's' for searches in WP_Term_Query rather than using 'search'?
$wpquery = new WP_Query( array( 's'=>'search term' ) );
$wptermquery = new WP_Term_Query( array( 'search'=>'search term' ) );
Not entirely sure why there's a differentiation between how a search term is used in the query args. For the sake of standardization and a reduction in confused developers (like I was about 30 minutes ago) I think this is worth some consideration.
Attachments (1)
Change History (8)
#1
@
6 years ago
- Keywords needs-patch good-first-bug added; dev-feedback removed
- Version changed from 5.5.3 to 4.6
This ticket was mentioned in PR #780 on WordPress/wordpress-develop by JWardee.
6 years ago
#2
- Keywords has-patch has-unit-tests added; needs-patch removed
The 'search' parameter takes precendence if both 's' and 'search' are populated. I've included two unit tests:
- Test that the 's' returns the correct terms
- Test that 'search' takes precedence when both 's' and 'search' are used
This is my first pull request so please let me know if anything needs amending! :)
Fixes: https://core.trac.wordpress.org/ticket/51811
Trac ticket:
github-actions[bot] commented on PR #780:
6 years ago
#3
Hi @JWardee! 👋
Thank you for your contribution to WordPress! 💖
It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!
No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.
Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.
More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post.
Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.
If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.
The Developer Hub also documents the various coding standards that are followed:
- PHP Coding Standards
- CSS Coding Standards
- HTML Coding Standards
- JavaScript Coding Standards
- Accessibility Coding Standards
- Inline Documentation Standards
Thank you,
The WordPress Project
This ticket was mentioned in PR #6746 on WordPress/wordpress-develop by @thehercules.
2 years ago
#4
Fixes Ticket #51811
For searching, in addition to search, now just like in WP_Query class we can pass 's' as a parameter. This aims in keeping the code consistent.
@thehercules commented on PR #6746:
2 years ago
#5
@westonruter I am not sure why the unit tests are failing, also there is no re-running jobs option. Can you guide me on how should I proceed further.
@thehercules commented on PR #6746:
2 years ago
#6
Hey @mukeshpanchal27 , I have made the suggested changes. Can you review them.
@
2 months ago
Refreshed patch for current trunk. Adds 's' as alias for 'search' in WP_Term_Query for consistency with WP_Query. 'search' takes precedence when both are provided. 3 unit tests, all 45 term query tests pass.
This ticket was mentioned in PR #11696 on WordPress/wordpress-develop by @motylanogha.
6 weeks ago
#7
WP_Query, WP_User_Query, and WP_Comment_Query all accept s as a shorthand alias for search. WP_Term_Query did not, so authors switching between query classes were silently dropping their search criterion.
This PR registers s as a recognized argument and copies it onto search when search is not explicitly set, preserving precedence for the long form.
Tests cover:
sreturns the same matches assearchsearchtakes precedence when both are providedsreturns empty for no-match input
Complements GH-780 and GH-6746.
Hi there, welcome back to WordPress Trac! Thanks for the ticket.
Yes, I think it would make sense to have
sas an alias forsearchhere inWP_Term_Query.Changing the version to 4.6 as the earliest applicable, since
WP_Term_Querywas introduced in [37572] / #35381.That said, the
searchargument forget_terms()was introduced in [6799], so the inconsistency dates back to WordPress 2.5.