[wp-trac] [WordPress Trac] #34211: Ability to specify fields WP_Query can search
WordPress Trac
noreply at wordpress.org
Sun Oct 11 17:57:14 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 | Resolution:
Keywords: | Focuses:
-------------------------+------------------------------
Comment (by akibjorklund):
This is a common requirement for sites that are more complex than blogs.
Typically this issue is solved with a plugin that creates their own
database tables or by integrating WordPress with external search
providers. I think the ability to search the content is a basic feature of
a CMS. This is why I think it is something WordPress too should definitely
be able to do somehow – in a way that would serve common use cases.
A simplest possible solution to the problem I can think of – that still
''could'' be scalable – is to add a parameter to WP_Query that would allow
you do define a single meta key that would be included in the search. If
one would want multiple meta values to be searched, one would have to
programmatically concatenate all those values into a single meta value
every time a post is saved. One can already do LIKE in `meta_compare`, but
ordering is not affected and searching terms across columns will not work
(searching `foo bar` when`foo` is in content and `bar` in meta field will
not find anything).
The downside of this approach compared to the one proposed above would be
to not be able to define fields to query dynamically per query. And also
there would be migration issues, when the definition of included fields
(or terms!) would change. Some kind of indexing precess should exist. That
could be left to plugin authors I guess. With this approach one could
still have multiple indexes with different set of fields though, which
could be helpful.
I'm not sure though that this approach would fly, because it would feel
unintuitive to developers to be limited to a single meta field. To make it
not so unintuitive, a lot more code would have to be written to make the
indexing of content automatic.
The API could look something like this: `register_search_index( $name,
$meta_fields, $taxonomies = array() );`. Plus WP_Query would have a new
field `search_index`.
I'm willing to write some code if this is a direction that more people
feel worth exploring.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34211#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list