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

1 Answer 1


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.

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.