Skip Navigation

[Resolved] Repeater fields sort order based on backend drag and drop

This support ticket is created 6 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 1 voice.

Last updated by pharmaklaus 6 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#923039

I am using this workaround to sort items based on backend order defined via drag and drop.
https://toolset.com/forums/topic/output-repeater-fields-in-their-drag-and-drop-order-in-wp-admin-edit-screen/#post-908557

In my case using the proposed workaround works for the sort order but breaks the pagination on other views, where there are archive.

add_filter( 'wpv_filter_query', function ( $query_args, $args, $view_id) {
    if (( $view_id == 10448 ) || ($view_id == 10734) || ($view_id == 11714) || ($view_id == 11401) || ($view_id == 11718)) { // if displaying a View with ID equal to 374
        $view_ids = array($view_id);
        if (in_array($view_id, $view_ids)) {
            $args = array(
                'meta_key' => 'toolset-post-sortorder',
                'orderby' => 'meta_value_num',
                'order' => 'ASC',
            );
        }
    }

    return array_merge($query_args, $args);
}, 199, 3 );
#923096

I modified the code according to
https://toolset.com/forums/topic/wpv_filter_query/#post-306269

It seems that sorting and pagination works both.

add_filter( 'wpv_filter_query', function ( $query_args, $args, $view_id) {

    if (!in_array ( $view_id , [ 10448, 10734, 11714, 11401, 11718 ]  )){ // whatever views are concerned by this pb
        return $query_args;
    }
    else {
        $query_args['orderby'] = "meta_value_num";
        $query_args["meta_key"] =  "toolset-post-sortorder" ;
        $query_args["meta_type"] = "numeric";
    }
    return $query_args;
}, 199, 3 );