With the following code (in functions.php) my posts (of CPT event) are ordered by _end_date instead of _start_date. What’s the proper solution to this as of WP 3.1.3? Of course I’d like to avoid using deprecated meta_key
.
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() ) {
$query->set( 'post_type', 'event' );
$query->set( 'meta_key', '_start_date' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
$query->set( 'meta_query', array(
array(
'key' => '_end_date',
'value' => time(),
'compare' => '>=',
'type' => 'numeric'
)
)
);
}
return $query;
}