REST API – Ordering by ACF Date field
-
Hello, I am having problems ordering users by an ACF datepicker field.
Datepicker return format is Ymd.
I don’t have problems ordering fields that aren’t a date.
My code is:
function order_rest_user_query($query_vars, $request) { $orderby = $request->get_param('orderby'); if (isset($orderby) && $orderby === 'activo') { $query_vars["orderby"] = "meta_value"; $query_vars["meta_key"] = "activo"; } if (isset($orderby) && $orderby === 'fecha_alta') { $query_vars["orderby"] = "meta_value_num"; $query_vars["meta_key"] = "fecha_alta"; } return $query_vars; } add_filter( 'rest_user_query', 'order_rest_user_query', 10, 2);The endpoint I am using is:
https://xxxxx/wp-json/wp/v2/users?context=edit&page=1&per_page=10&orderby=fecha_alta&order=asc
I have tested a lot of things with different order as result but aren’t right:
A lot of thanks.
Regards
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘REST API – Ordering by ACF Date field’ is closed to new replies.