1
我想獲取所有具有meta_value書,研究,藝術的文章。但是,當我把meta_query系統3陣列不返回任何東西,但如果我把在線2陣列它的工作Wordpress meta_query比較3元值與相同的元鍵
// this working
$args = array(
'numberposts' => 10,
'post_type' => 'content',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'media_type',
'value' => 'Book',
'compare' => 'LIKE'
),
array(
'key' => 'media_type',
'value' => 'Study',
'compare' => 'LIKE'
)
)
);
//this now working
$args = array(
'numberposts' => 10,
'post_type' => 'content',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'media_type',
'value' => 'Book',
'compare' => 'LIKE'
),
array(
'key' => 'media_type',
'value' => 'Study',
'compare' => 'LIKE'
),
array(
'key' => 'media_type',
'value' => 'Art',
'compare' => 'LIKE'
)
)
);
此解決方案返回null Array() –
奇怪的是,我猜別的東西導致了這個問題。任何額外的'pre_get_posts'過濾器?你能分享相關的SQL查詢嗎?你可以從它得到它:'$ q = WP_Query($ args);回聲$ q->請求;' – birgire
葉我現在不爲什麼不工作..所以我相關的SQL查詢 - >> SELECT SQL_CALC_FOUND_ROWS wpnew_posts.ID FROM wpnew_posts INNER JOIN wpnew_postmeta ON(wpnew_posts.ID = wpnew_postmeta。 (wpnew_posts.post_status ='publish'或wpnew_posts.post_status ='private')AND((wpnew_postmeta.meta_key ='media_type'AND CAST(wpnew_postmeta.meta_value AS CHAR )IN('Art','Book','Study')))GROUP BY wpnew_posts.ID ORDER BY wpnew_posts.post_date DESC LIMIT 0,10 –