[wp-trac] [WordPress Trac] #34211: Ability to specify fields WP_Query can search
WordPress Trac
noreply at wordpress.org
Thu Oct 8 11:59:11 UTC 2015
#34211: Ability to specify fields WP_Query can search
-------------------------+-----------------------------
Reporter: paulwilde | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
Currently the `s` parameter in WP_Query is hardcoded to only search in the
`post_title` and `post_content` fields. A decent enhancement would be if
you could also specify which postmeta fields it can search into as well.
Also allowing more fine-grained control so that it can search only
postmeta fields and ignore `post_title` and `post_content` as well.
Something along the lines of:
{{{
's' => 'foo',
's_fields' =>'title',
's_meta_fields' => array( 'custom_field_1', 'custom_field_2' ),
}}}
`s_fields` can a string/array of either post_title and/or post_content.
Setting it to false would disable searching these fields and assume you
have set custom meta fields to search for instead. By default it would be
`array( 'title', 'content' )`.
`s_meta_fields` can accept a string/array of postmeta field names to
search for. By default it would be `false`.
A decent use case would be the [https://wordpress.org/plugins/search-by-
sku-for-woocommerce/ Search by SKU for Woocommerce] plugin which resorts
to writing a custom query.
I assume the only real concern would be performance.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34211>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list