WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] meta_key not return results in get_posts (5 posts)

  1. woogychuck
    Member
    Posted 4 years ago #

    When calling the get_posts function, I'm look for all posts that have a CustomField named 'ShowNav' that has a value of 'false'

    I have confirmed that there are multiple published posts with this key/value combination, but both of the following function calls return an empty array.

    $postlist = get_posts('meta_key=ShowNav');
    
    $postlist = get_posts('meta_key=ShowNav&meta_value=false');
    
    $args = array(
    	'meta_key' => 'ShowNav',
    	'meta_value' => 'false'
    	);
    $postlist = get_posts($args);

    I'm actually using 2.9.2, but it wasn't an option in the select

  2. woogychuck
    Member
    Posted 4 years ago #

    Please disregard this, it was a user error on my part. I mistakenly thought this function would return posts and pages, when it only returns posts.

  3. MichaelH
    Member
    Posted 4 years ago #

    What about:

    $args = array(
    	'meta_key' => 'ShowNav',
    	'meta_value' => 'false',
            'post_type' => 'any'
    	);

    or

    $args = array(
    	'meta_key' => 'ShowNav',
    	'meta_value' => 'false',
              'post_type' => array('post','page')
    	);
  4. maorb
    Member
    Posted 3 years ago #

    Is it possible to get_posts and filter them more than one meta key?

  5. maorb
    Member
    Posted 3 years ago #

    Is it possible to get_posts and filter them more than one meta key?

Topic Closed

This topic has been closed to new replies.

About this Topic