I have an issue that is doing my head in, I'm trying to sort my posts using pre_get_posts
by and ACF field that is a text field.
Here is my code:
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() ) {
return $query;
}
if( $query->is_main_query() && $query->is_tax('locations')) {
$query->set('meta_key', 'level');
$query->set('orderby', 'meta_value');
$query->set('order', 'DESC');
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
In the ACF config, it's set to text and the values of this text can be Bronze, Silver, Gold etc.
UPDATE I've now changed the level field to a number and switch it round 1 = Bronze, 2 = Silver etc.
Still, I get nothing.
When I run the below nothing gets returned.
Any ideas?