这是我在模板函数中的函数。php。
问题是这是可行的:
function ajax_search_action_do(){
global $wp_query;
$search = $_POST[\'search_value\'];
$country = $_POST[\'country_value\'];
$args = array(
\'s\' => $search,
\'posts_per_page\' => 10,
);
$wp_query = new WP_Query( $args );
get_template_part( \'search-results\' );
exit;
}
但这不是:function ajax_search_action_do(){
global $wp_query;
$search = $_POST[\'search_value\'];
$country = $_POST[\'country_value\'];
$args = array(
\'s\' => $search,
\'posts_per_page\' => 10,
\'tax_query\' => array(
array(
\'taxonomy\' => \'country\',
\'field\' => \'id\',
\'terms\' => $country,
),
),
);
$wp_query = new WP_Query( $args );
get_template_part( \'search-results\' );
exit;
}
所以,当只有搜索词时,它就起作用了,我得到了正确的结果。但是,当我尝试将其与tax\\u查询结合使用时,搜索词不起作用,只有tax\\u查询起作用。如何使这两个条件一起工作?
生成的查询:
`SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (8) ) AND (((wp_posts.post_title LIKE \'%test%\') OR (wp_posts.post_content LIKE \'%test%\'))) AND wp_posts.post_type IN (\'post\', \'page\', \'attachment\') AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'future\' OR wp_posts.post_status = \'draft\' OR wp_posts.post_status = \'pending\' OR wp_posts.post_author = 1 AND wp_posts.post_status = \'private\') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10`