Hello ACF users,
And thanks in advance for everything you’re doing.
I’m facing a problem while trying to order posts by a custom field.
I created a custom field “montant_propose”, set as a number, used in a custom post type “annonce”.
I want to order my posts in an elementor “posts” widget. In a theme child, I set the query by adding :
add_action(‘elementor/query/offre_query’, function($query){
$query->set(‘orderby’, ‘meta_value’);
$query->set(‘meta_key’, ‘montant_propose’);
$query->set(‘order’, ‘ASC’);
});
But then my posts are sorted… alphabetically (100, 120, 55, 59, 8…).
And an echo gettype(get_field(‘montant_propose’), xxx) confirms that my number field is indeed a string.
Would you have any idea why my number field is considered as a string ? What am I doing wrong right here ?
I’m using ACF 5.8.8 and WP 5.3.2.
Cheers,
Corentin from Toulouse
$query->set('orderby., 'meta_value_num');