0

want to query 100 posts, but only those which do not have a featured image attached. I am using meta_key method for this with WP_Query as such:

$args = array(
   'post_type'  => 'post',
   'posts_per_page' => 100,
    'meta_query' => array(
        array(
         'key' => '_thumbnail_id',
         'compare' => 'NOT EXISTS'
        ),
    )
);

But Not work with me

Any help ?

  • Please explain But Not work with me – Pieter Goosen Jul 20 '16 at 9:08
  • my code its not show me any result – Khalid Almallahi Jul 20 '16 at 10:51
  • use if statement like this if(!has_post_thumbnail()) – user93819 Jul 21 '16 at 2:33
1

Try this code , its working for me

value=>'?' 

because(value was required for NOT EXISTS comparisons to work correctly prior to 3.9. You had to supply some string for the value parameter. An empty string or NULL will NOT work. However, any other string will do the trick and will NOT show up in your SQL when using NOT EXISTS.)

For more information about value=>? please refer this link

$args = array(
  'post_type'  => 'post',
  'posts_per_page' => 100,
  'meta_query' => array(
     array(
       'key' => '_thumbnail_id',
       'value' => '?',
       'compare' => 'NOT EXISTS'
     )
  ),
);
$new_query = new WP_Query( $args );
  • Downvoted as you offer no explanation to the ode you just dumped. Please file an edit and explain your code and also point out what makes your code different than what the OP used – Pieter Goosen Jul 20 '16 at 9:19
  • 1
    Try this code , its working for me REALLY??? I have asked you this: Please file an edit and explain your code and also point out what makes your code different than what the OP used. What you have posted is noise which does not fit what I have asked you. If you go and read the docs, if you pass NOT EXISTS to compare, you do NOT need to specify the value parameter, so I again ask you, what is different from your code than what the OP posted – Pieter Goosen Jul 20 '16 at 10:18
  • what can it add in value ? – Khalid Almallahi Jul 20 '16 at 10:51
  • means? please explain @Khalid Almallahi – Navin Bhudiya Jul 20 '16 at 10:56
  • @Bhudiya Navin He is asking the meaning of this line 'value' => '?', And if possible please explain all lines of your code at least by putting comments on every line so that your answer can be helpful for future viewers also. – Rishabh Jul 20 '16 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.