-1
看到了類似的問題貼出來,但沒有解答...... 我已經爲一個WP_Query的參數傳遞給:WP_Query ARGS訂單被忽略
function get_url_shortcode($atts, $content =null) {
$query_args = array(
'posts_per_page' => -1,
'order_by' => 'title',
'order' => 'ASC',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $atts[cat1],
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $atts[cat2]
)
),
'post_type' => 'product'
);
remove_all_filters('posts_orderby');
$loop = new WP_Query($query_args);
var_dump($loop->request);
}
該簡碼功能不會產生正確的結果,但標題中的OrderBy,我在args中設置的不僅被忽略,而且當我轉儲生成的Select時,OrderBy看起來被設置爲Post_Date ASC。
string(567) "SELECT wp_posts.* FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id) WHERE 1=1 AND (wp_term_relationships.term_taxonomy_id IN (1554,9907,9908,9909,9910,9911,9912) AND tt1.term_taxonomy_id IN (357,1555,1556,1557,1559,1560,1561,1562,1570,1571,1572,1573,1644,6309,7903)) AND wp_posts.post_type = 'product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC "
我已關閉所有插件並恢復爲默認主題TwentySixteen並獲得相同的結果。這在代碼的其他地方也會發生,因爲其他列表(而不是使用此簡碼功能生成)也未被正確排序。所以我不認爲這是我的代碼專門,但某處覆蓋我的查詢,我不知道在哪裏或如何跟蹤它。
任何想法? 謝謝, 豐富