我有兩個搜索查詢。用默認方式搜索與參數匹配的任何帖子標題。如何結合這兩個WordPress搜索查詢?
第二個查詢設置爲使用搜索查詢的搜索關鍵字「SKU」搜索任何帖子。
我想結合這兩個查詢,以便搜索將返回標題OR SKU匹配搜索項的任何帖子。
首先查詢:
$args = array(
's' => apply_filters('yith_wcas_ajax_search_products_search_query', $search_keyword),
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => $ordering_args['orderby'],
'order' => $ordering_args['order'],
'posts_per_page' => apply_filters('yith_wcas_ajax_search_products_posts_per_page', get_option('yith_wcas_posts_per_page')),
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
)
)
);
第二個查詢:
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'orderby' => $ordering_args['orderby'],
'order' => $ordering_args['order'],
'posts_per_page' => apply_filters('yith_wcas_ajax_search_products_posts_per_page', get_option('yith_wcas_posts_per_page')),
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
),
array(
'key' => '_sku',
'value' => apply_filters('yith_wcas_ajax_search_products_search_query', $search_keyword),
'compare' => 'LIKE'
)
)
);
我如何結合這兩個查詢,並返回任何帖子的標題或SKU與搜索詞匹配?
我很遺憾地告訴你,但你可能即將有組合這些_meta_queries_問題。看看[這](http://stackoverflow.com/questions/18966416/wordpress-query-with-sub-relations/18971049#18971049)。在你的第二個查詢中,你有兩個以'AND'關係組合的meta_query,並且你需要使用'OR'關係將這兩個條件結合到第一個查詢的條件中,這似乎不可能。 – mathielo