So here is my query:
$args = array(
'post_type' => 'Event',
'posts_per_page' => 1000,
'meta_key' => 'event_informations_show_on_the_homepage',
'meta_value' => 'Show on the homepage',
'meta_compare' => '==',
'meta_key' => 'event_informations_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$loop = new WP_Query( $args );
I want to select all posts that have the metabox event_informations_show_on_the_homepage
and the value of the metabox event_informations_show_on_the_homepage
and order by the date metabox which is stored as a timestamp and is called event_informations_date
.
What am I doing wrong?
Hopefully I’m not barking up the wrong tree here.
You can use the key ‘meta_query‘ to filter posts by multiple meta keys like so:
What WordPress is doing here is creating multiple wheres against the same column by using innerjoins on the same table, each time using a different alias. It’s pretty cool & is probably the fastest way to query like that.
For more information see here: http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
Hope this helps 🙂