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.

I am trying to count my custom post type called 'appointments' that match two meta data values .

The meta data keys are 'location' and 'timestamp'

So in english my query is: How many appointments are scheduled at Location at Time

How can this be done?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
$args = array(
    'post_type'  => 'appointments',
    'meta_query' => array(
        'relationship' => 'AND',
        array(
            'key'   => 'location',
            'value' => $place //set this somewhere
        ),
        array(
            'key'   => 'timestamp',
            'value' => $time //set this somewhere
        )
    )
);
$posts = new WP_Query( $args );

Docs: WP_Query

You have the flexibility to add just about anything else you need to that, for example, post_status.

share|improve this answer
    
Thanks - That looks good, but how do I count it? I can run a $c++ in a loop, but I'd rather do it in the query if I can instead –  Jay West Feb 1 '12 at 5:08
    
count( $posts ) and setup_postdata‌​, respectively. Alternately, you can use WP_Query args in query_posts() –  m0r7if3r Feb 1 '12 at 18:44
1  
$count = $posts->found_posts; // worked for the count –  Jay West Feb 1 '12 at 19:33
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.