我有一个基于这些参数的自定义循环(如下所示),由于某种原因,在运行时,返回的SQL包含以下片段:
。。。和wp\\U帖子。ID=-1。。。
我没有从db得到任何结果。如果在没有此片段的情况下对db运行查询,则会得到所需的结果。有人能指出导致这种行为的参数列表有什么问题吗?
$args = array (
\'post_status\' => \'draft\',
\'posts_per_page\' => 10,
\'category_name\' => $language_sql_param, //fixed
\'meta_query\' => array(
array(
\'key\' => \'review_rating\',
\'value\' => \'3\',
\'compare\' => \'>\',
\'type\' => \'NUMERIC\',
),
),
\'cache_results\' => false,
\'update_post_meta_cache\' => false,
\'update_post_term_cache\' => false,
\'suppress_filters\' => true,
\'meta_key\' => \'review_id\',
\'orderby\' => \'meta_value_num\',
);
$wp_query = new WP_Query( $args );
修改后的问题:我正在根据帖子所属的类别筛选帖子,在我的情况下,它们是国家代码。下面是WP在设置
$language_sql_param
对此:
$language_sql_param = \'us,gb,ca,au,ie\'
它工作得很好,并为我在英语国家的帖子返回ID。
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)
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (20,21,28,36,37) )
AND wp_posts.post_type = \'post\'
AND (wp_posts.post_status = \'draft\')
AND (wp_postmeta.meta_key = \'review_id\'
AND (mt1.meta_key = \'review_rating\'
AND CAST(mt1.meta_value AS SIGNED) > \'3\') )
GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value+0 DESC
LIMIT 0, 10
当我设置
$language_sql_param = "\'de,ch\'"
, 我得到以下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)
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
INNER JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
WHERE 1=1
AND wp_posts.ID = -1
AND ( wp_term_relationships.term_taxonomy_id IN (27,34) )
AND wp_posts.post_type = \'post\'
AND (wp_posts.post_status = \'draft\')
AND (wp_postmeta.meta_key = \'review_id\'
AND (mt1.meta_key = \'review_rating\'
AND CAST(mt1.meta_value AS SIGNED) > \'3\') )
GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value+0 DESC
LIMIT 0, 10
SQL有这个额外的
AND wp_posts.ID = -1
. WordPress似乎正确地为我正在筛选的类别生成IN子句,如
AND (wp_term_relationships.term_taxonomy_id IN (27,34))
, 但因为WordPress不知何故添加了
AND wp_posts.ID = -1
条件没有返回帖子。
在哪里AND wp_posts.ID = -1
来自哪里?