Call Chris at (615) 521-1890 for a free quote.
615.521.1890
Nashville Interactive - Home

Blog

Using Checkboxes and Custom Meta Values With WP_Query

Aug 2 2011

I had the hardest time (harder than it should have been anyway) trying to figure out how to filter my posts using WP_Query and the value of a checkbox (checked or not). As it turns out the value is “on”. See an example below of that and how to use multiple custom meta values to filter your content.

$args = array(
‘post_type’ => ‘athletes’,
‘posts_per_page’ => -1,
‘orderby’ => ‘menu_order’,
‘order’ => ‘ASC’,
‘meta_query’ => array(
array(
‘key’ => ‘dbt_gender’,
‘value’ => ‘male’
),
array(
‘key’ => ‘dbt_basketball’,
‘value’ => ‘on’
)

)
);

$the_query = new WP_Query( $args );

while ($the_query->have_posts()) : $the_query->the_post();

// DO YOUR LOOP MESS HERE!!!

endwhile;