I have written a plugin which can store a table of technical specifications for each post (product) in an own database table.
For the search function of the site I want to add a custom parameter to the array passed to WP_Query()
.
I have no clue where to register this custom parameter so that it is handled by the plugin as soon as WP_Query()
executes the search.
Is there a hook that I can use in the plugin to restrict the posts found by WP_Query()
to a certain set matching the specs given?
Or do I eventually have to build the entire query using SQL?
See the following example: next to “standard”-parameters I have a custom parameter _spec
its value I want to be parsed in some way by the plugin.
<?php
new WP_Query(
array(
's' => 'some keyword', //keyword criterion
'category' => 'some category', //taxonomy criterion
'_spec' => 'year_min=1980;year_max=2010', //custom criterion to be handled by the plugin
)
);
?>
After further research I figured out a solution. Given the following
WP_Query
:You can handle custom parameters using
pre_get_posts
in combination withposts_where
:PS: Take a look at http://codex.wordpress.org/Class_Reference/WP_Query#Filters for manipulating other parts of the SQL-query (e.g. JOIN)