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