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'm using Event Calendar 3. Since there seems to be no easy way of querying all upcoming events as posts, I tried it this way, getting the IDs from the DB and querying the posts from that:

<?php if(!ec3_check_installed(__('Upcoming Events','ec3')))
    return;
global $ec3,$wpdb,$wp_version;

$calendar_entries = $wpdb->get_results(
    "SELECT
        p.id AS id
    FROM $ec3->schedule s
    LEFT JOIN $wpdb->posts p ON s.post_id=p.id
    WHERE p.post_status='publish'
    AND end>='$ec3->today' $and_before
    ORDER BY start $limit_numposts", OBJECT_K
); 

$args = array(
    'post_type' => 'post',
    'post__in' => $calendar_entries,
    'orderby' => 'id',
    'order' => 'DESC'
);

$query = new WP_Query( $args );

It doesnt work, obviously because the array looks like this, if I var_dump it:

array(2) {
    [37]=> object(stdClass)#2183 (1) { 
        ["id"]=> string(2) "37"
    }
    [8]=> object(stdClass)#2186 (1) { 
        ["id"]=> string(1) "8" 
    } 
} 

How can I use this array for my query?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Try this after your $wpdb query:

// collect calendar id's
$ids = array();
foreach( $calendar_entries as  $calendar_entries):
        array_push( $ids, $calendar_entries->id );
endforeach;

// query the above calendar id's
$args = array(
    'post_type' => 'post',
    'post__in' => $ids,
    'orderby' => 'id',
    'order' => 'DESC'
);
$query = new WP_Query( $args );

You can also modify the WP_Query by using posts_where, posts_join and posts_clauses.

share|improve this answer
    
That's perfect. Thank you very much! –  Lord_Mord Jul 23 '13 at 12:44
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.