看过类似的问题,但还没有答案...... 我已将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);
}
这个短代码函数确实产生了正确的结果,但是我在args中设置的TitleBy不仅被忽略,而且当我转储生成的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并获得相同的结果。这也发生在代码的其他地方,因为其他列表( 不 使用此短代码函数生成)也没有正确排序。所以我不认为这是我的代码具体,但某些地方覆盖了我的查询,我不知道在哪里或如何跟踪它。
有什么想法吗? 谢谢, 富