WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have a custom post called event, but I need to query only those posts which have a custom metabox(is a checkbox) called `Show On The Homepage: and only if that checkbox is checked.

    $args = array( 'post_type' => 'Event','posts_per_page' => 1000 );
    $loop = new WP_Query( $args );
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

My question is there a way to query this, or I will have to do a get_meta in the loop and check each one with an if statement

share|improve this question

Since you're using WP_Query(), you should consult the Codex entry for WP_QUery(). It lists all of the parameters that can be passed to the arguments array.

In this case, you want to use the post custom meta parameters.

Assuming your custom meta key is _show_on_front, and your value is true or false:

$custom_query_args = array(
    'post_type' => 'Event',
    'posts_per_page' => 1000
    'meta_key' => '_show_on_front',
    'meta_value' => true
$custom_query = new WP_Query( $custom_query_args );

For more complex examples, consult the linked Codex entry.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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