Wordpress还提供了更多过滤器,可以使用过滤器更改wp查询。如果这对您有帮助的话,我需要什么逻辑来使用过滤器覆盖下面的代码示例查询。
add_filter( \'posts_where\', \'posts_where_condition_search\' );
$wp_query = new WP_Query(
array(
\'post_type\' => \'press-release\',
\'posts_per_page\' => -1,
)
);
remove_filter( \'posts_where\', \'posts_where_condition_search\' );
function posts_where_condition_search( $where ){
$search_string = \'test\';
if( isset( $_POST[\'search\']) && !empty($_POST[\'search\']) )
$search_string = $_POST[\'search\'];
if( empty($search_string) )
return $where;
// add your multiple condition here and write your custom filter
$where .= " AND (((wp_posts.post_title LIKE \'%$search_string%\') OR (wp_posts.post_content LIKE \'%$search_string%\'))) ";
//$where .= " AND (((wp_posts.post_title LIKE \'%$search_string%\') OR (wp_posts.post_content LIKE \'%$search_string%\'))) ";
//$where .= " AND (((wp_posts.post_title LIKE \'%$search_string%\') OR (wp_posts.post_content LIKE \'%$search_string%\'))) ";
return $where;
}
https://codex.wordpress.org/Class_Reference/WP_Query#Filters