Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#51811 new enhancement

Query inconsistency between WP_Query and WP_Term_Query

Reported by: tonydjukic's profile tonydjukic 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:


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.

Change History (3)

#1 @SergeyBiryukov
3 years ago

  • Keywords needs-patch good-first-bug added; dev-feedback removed
  • Version changed from 5.5.3 to 4.6

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Yes, I think it would make sense to have s as an alias for search here in WP_Term_Query.

Changing the version to 4.6 as the earliest applicable, since WP_Term_Query was introduced in [37572] / #35381.

That said, the search argument for get_terms() was introduced in [6799], so the inconsistency dates back to WordPress 2.5.

This ticket was mentioned in PR #780 on WordPress/wordpress-develop by JWardee.

3 years ago

  • 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! :)


Trac ticket:

github-actions[bot] commented on PR #780:

3 years ago

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:

Thank you,
The WordPress Project

Note: See TracTickets for help on using tickets.