Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to grab the 5 most recent posts and have it exclude posts in an array that is already defined ($exclude), sticky posts and any posts that are checked off as a featured post (i.e. with the custom field "my_featured_post" set to 1)

I tried:

$args = array('post__not_in' => $exclude,
    'ignore_sticky_posts' => 1,
    'posts_per_page' => 5,
    'meta_query'=> array(
        array(
        'key'=>'my_featured_post',
        'value'=>'1',
        'compare'=>'!='
        )
    )
);
$query = new WP_Query($args);

and :

$args = array('post__not_in' => $exclude,
                      'ignore_sticky_posts' => 1,
                      'paged'=>1,
          'posts_per_page' => 5,
          'meta_key'=>'my_featured_post',
          'meta_value'=>'1',
          'meta_compare'=>"!="

                    );

Neither returned any posts. If i remove the references to meta in either query, it returns a mix of posts set as "my_featured_posts" and not set as such.

Am I going about this wrong?

Thanks, gS

share|improve this question
add comment

1 Answer

Try adding the type parameter:

$args = array('post__not_in' => $exclude,
    'ignore_sticky_posts' => 1,
    'posts_per_page' => 5,
    'meta_query'=> array(
        array(
        'key'=>'my_featured_post',
        'value'=> 1,
        'type' => 'numeric', // assuming your custom_value is an int, not a string.
        'compare'=>'!='
        )
    )
);
$query = new WP_Query($args);
share|improve this answer
    
This did not work - it returns posts with my_featured_post set to 1 and those without it set at all... –  setterGetter Jul 26 '12 at 14:17
    
I'd missed the quotes around 'numeric', fixed now. Was that it? –  moraleida Jul 26 '12 at 14:22
    
Huh? Can you run that by me again? –  setterGetter Jul 26 '12 at 15:10
    
Nevermind last comment. No dice :\ -- I was thinking maybe i have the wrong key - but when I set compare to just "=" I get the same exact results instead of a subset of just featured posts... –  setterGetter Jul 26 '12 at 15:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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