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 trying to query all-in-one-event-calendar's custom post type ai1ec_event and normal wordpress posts in a slider on my home page. That works pretty well.

Now I want to query only the posts with the custom field value "teaser", but that returns just normal posts, not the events.

<?php
query_posts( array(
'post_type'=>array('post','ai1ec_event'),   
'posts_per_page' => 50,
'meta_query' => array(
    array(
        'key' => 'teaser',
        'value' => 'on'        
    )
)
);
?>

Even if I leave out the post type query:

<?php
query_posts( array(
'meta_query' => array(
    array(
        'key' => 'teaser',
        'value' => 'on'        
    )
)
);
?>

it only returns posts, no events.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I'm afraid WP_Query is not able to fetch (Posts with custom field) or (ailec_even). You'll have to query the firs one, than the second one and merge those arrays. Use WP_Query instead of query_posts.

I've just tried it on my local installation and this code called from index.php of twentytwelve works (brings post with title "Hello post" and ai1ec_event with title "Event" - both with custom field "teaser" with value "on"

$events_query = new WP_Query( array('post_type' => array('ai1ec_event', 'post'), 'meta_query' => array( array( 'key' => 'teaser', 'value' => 'on' ) )) );
while ( $events_query->have_posts() ) :
    $events_query->the_post();
    echo get_the_title() . '<br/>';
endwhile;

Have to say that both (post end event) were created by admin user - I've checked the code and there is an extensive part with custom capabilities.

share|improve this answer
    
I dont think, this will work. I reported the wrong behaviour. See the corrected question above. I didnt notice it first, but including the meta key query ALWAYS returns just the posts. –  Lord_Mord Feb 2 '13 at 20:00
    
does your ai1ec_event contains teaser custom meta field? –  david.binda Feb 2 '13 at 20:10
    
Yes it does, and it is switched on. –  Lord_Mord Feb 2 '13 at 20:12
    
I' just checked this taks on my local install - se modified answer above. –  david.binda Feb 2 '13 at 20:39
    
I checked it twice: For me that only returns posts. What can be the reason for this behaviour? –  Lord_Mord Feb 2 '13 at 20:51

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.