Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

<?php
    $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
add comment

1 Answer

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:

<?php
$custom_query_args = array(
    'post_type' => 'Event',
    'posts_per_page' => 1000
    // INSERT POST CUSTOM META PARAMETERS HERE
    '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
add comment

Your Answer

 
discard

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.