admin管理员组文章数量:1122846
I have a plugin that has following code
$posts = new WP_Query([
'post_type' => 'campaign',
'meta_query' => [
'relation' => 'AND',
[
'key' => 'external_id',
'value' => 'save-trees',
'compare' => '='
],
[
'key' => 'source',
'value' => 'website',
'compare' => '='
]
]
]);
And I logged what this above piece of code's equivalent sql query is executed using
$query_sql = $posts->request;
error_log('sql executed is ---------------'.$query_sql. PHP_EOL, 3, $pluginlog);
and this gave the log
sql executed is ---------------
SELECT wp_posts.ID
FROM wp_posts 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_postmeta.meta_key = 'external_id' AND wp_postmeta.meta_value =
'save-trees' )
AND
( mt1.meta_key = 'source' AND mt1.meta_value = 'website' )
) AND ((wp_posts.post_type = 'campaign' AND (wp_posts.post_status =
'publish'))) AND wp_posts.post_type <> 'campaign'
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 10
I am unable to understand why the sql query is returning with wp_posts.post_type <> 'campaign'
when I have the code as it is of posttype campaign
.
Could someone please explain ? Thanks in advance!
本文标签: pluginsWPQuery does not return the result even if the data is present in the database
版权声明:本文标题:plugins - WP_Query does not return the result even if the data is present in the database 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311114a1934623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论