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);

1 Answer 1

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);
1
  • Happy to help, @lingo! Commented Jan 24, 2017 at 20:52

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.