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.
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”
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.