Home Forums General Issues REST API – Order by ACF date field


REST API – Order 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:


    I have tested a lot of things with different order as result but aren’t right:

    A lot of thanks.


Viewing 1 post (of 1 total)

The topic ‘REST API – Order by ACF date field’ is closed to new replies.