Home Forums General Issues Cant query by custom field


Cant query by custom field

  • Hi there

    I’ve created a custom field called display, radio box, with values either yes or no.

    I’ve added yes to a couple of posts and try to query using the following but it won’t return any posts. Can you please help?

    $args = get_posts(array(
    ‘numberposts’ => 1,
    ‘post_type’ => ‘post’,
    ‘meta_key’ => ‘display’,
    ‘meta_value’ => ‘yes’

    // query
    $the_query = new WP_Query( $args );

    <?php if( $the_query->have_posts() ): ?>

    <?php endif; ?>

    <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>

  • Looking at what I can see of your code I don’t see anything that wrong. This is not a valid WP_Query argument 'numberposts' => 1, that I can find, but it should not effect the query since it should be ignored. This should probably be 'posts_per_page' => 1,

    If you re-post your code and use code tags around id so the the forum does not trash it I may be able to see more that might cause a problem.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.