我一直在用手撞墙,想弄明白这一点。
有人能向我解释一下为什么这个自定义wp\\U查询会产生两个不同的sql语句,一个用于索引页(正确),另一个用于类别页(错误)
function myFunction( $category )
{
if(!$category) return;
$query = array(
\'post_type\' => \'download\',
);
$query[\'tax_query\'][] = array(
\'taxonomy\' => \'download_category\',
\'terms\' => explode( \',\', $category ),
\'field\' => \'slug\'
);
$downloads = new WP_Query( $query );
return intval($downloads->found_posts);
}
索引sql(正确):
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 (20) ) AND wp_posts.post_type = \'download\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'refunded\' OR wp_posts.post_status = \'failed\' OR wp_posts.post_status = \'revoked\' OR wp_posts.post_status = \'abandoned\' OR wp_posts.post_status = \'active\' OR wp_posts.post_status = \'inactive\' OR wp_posts.post_status = \'private\') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
类别sql(错误):
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 (15) ) AND wp_posts.post_type IN (\'nav_menu_item\', \'post\', \'eddset\') AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'refunded\' OR wp_posts.post_status = \'failed\' OR wp_posts.post_status = \'revoked\' OR wp_posts.post_status = \'abandoned\' OR wp_posts.post_status = \'active\' OR wp_posts.post_status = \'inactive\' 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
它正在忽略post\\u类型,但无法找出原因?
非常感谢您的帮助。