I want to retrieve old Events from another WordPress instance and sort them by a meta value "date_from" (= start date) which is stored by ACF as yyyymmdd. The query works well except for the ORDER-part. I tried to order by another meta value, which does not work either. However, ordering does work with the same code in another project when I query the original WordPress database. Any ideas? Thanks! Here is my code:
$wpdb = new wpdb( $user, $pass, $db, $host );
$wpdb->set_prefix('zem_');
$wpdb->show_errors();
$args = array(
'post_type' => 'events',
'meta_key' => 'date_from',
'orderby' => 'meta_value', // order by start date (does not work! also meta_value_num)
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'date_from',
'value' => $today,
'compare' => '<', // get old events (works!)
),
),
);