0

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

1 Answer 1

0

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);
4
  • This did not work - it returns posts with my_featured_post set to 1 and those without it set at all... Jul 26, 2012 at 14:17
  • I'd missed the quotes around 'numeric', fixed now. Was that it?
    – moraleida
    Jul 26, 2012 at 14:22
  • Huh? Can you run that by me again? Jul 26, 2012 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... Jul 26, 2012 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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