0

I'm trying to filter posts based on the post type. If I add filter post_type => 'page', there will be posts included instead of pages. What would be the problem? The meta_key argument does not work either. I have Advanced Custom Fields plugin installed. Here is the code I'm using:

$args = get_posts(array(
    'numberposts'   => -1,
    'post_type'     => 'page',
    'meta_key'      => 'top-story', // true-false
    'meta_value'    => '1'
    ));

$the_query = new WP_Query($args);
2

Your $args array should not have the call to get_posts(). $args should just be an array:

$args = array(
    'numberposts'   => -1,
    'post_type'     => 'page',
    'meta_key'      => 'top-story', // true-false
    'meta_value'    => '1'
);

$the_query = new WP_Query($args);
  • Happy to help, @lingo! – Dave Romsey Jan 24 '17 at 20:52

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.