如果要扩展查询,应通过pre_get_posts
-滤器那就做一个"Custom Field" or meta query.
add_action( \'pre_get_posts\', \'wpse105969_extended_search\' );
function wpse105969_extended_search( $query )
{
// Make sure we got a search query
// and we\'re only modifying the main query.
if (
! $query->is_main_query()
AND \'\' === $query->get( \'s\' )
AND \'your_custom_post_type\' === $query->get( \'post_type\' )
)
return $query;
// Alter whatever you need: Make, Model, etc.
$query->set( \'meta_query\', array(
\'relation\' => \'OR\',
array(
\'key\' => \'color\',
\'value\' => \'blue\',
\'compare\' => \'NOT LIKE\'
),
array(
\'key\' => \'price\',
\'value\' => array( 20, 100 ),
\'type\' => \'numeric\',
\'compare\' => \'BETWEEN\'
)
) );
return $query;
}