I’ve a customized loop primarily based on these arguments (under), and for some motive when it is run, the SQL returned has this fragment:
… AND wp_posts.ID = -1 …
And I get no outcomes from the db. If I run the question towards the db with out this fragment, I get the outcomes I want. Might somebody, please, level out what’s unsuitable with argument listing that causes this conduct?
$args = array (
'post_status' => 'draft',
'posts_per_page' => 10,
'category_name' => $language_sql_param, //fastened
'meta_query' => array(
array(
'key' => 'review_rating',
'worth' => '3',
'examine' => '>',
'sort' => '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 );
Revised query:
I’m filtering posts primarily based on a class(s) they belong too, in my case they’re nation codes. Here is the SQL that WP generates once I set $language_sql_param
to this:
$language_sql_param = 'us,gb,ca,au,ie'
It really works superb and returns IDs for my posts for EN talking nations.
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 = 'submit'
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
Once I set $language_sql_param = "'de,ch'"
, I get this 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 = 'submit'
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
The SQL has this further AND wp_posts.ID = -1
. WordPress appears to accurately generate the IN clause for the classes I’m filtering, as in AND (wp_term_relationships.term_taxonomy_id IN (27,34))
, however as a result of WordPress in some way provides AND wp_posts.ID = -1
situation no posts are returned.
The place is AND wp_posts.ID = -1
coming from?