Skip Navigation

[Resolved] Output Repeater fields in their drag-and-drop order in wp-admin edit screen

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.

Our next available supporter will start replying to tickets in about 7.14 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 10 replies, has 5 voices.

Last updated by Twig 6 years, 3 months ago.

Assisted by: Beda.

Author
Posts
#907996

I followed https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/#displaying-repeatable-field-groups

Screenshot of my View's settings: hidden link

I'm getting the repeating fields to output but they're in the order I created them, not their drag-and-drop order. In other words, sorting by "Post date" in Ascending/Descending works as expected, but this doesn't match the drag-and-drop order.

Which "Order by" option do I need to select? Suggestion: Doesn't the View know when I'm rendering repeating fields and therefore shouldn't the *View ordering* be irrelevant and they *always* display in drag-and-drop order regardless of the View's "order by" setting? Or should there be an "order by drag-and-drop" option?

#908557

Hi Clifford, I see what you're describing. Let me reach out to my developers to see if this is a bug, an oversight, or if the ordering functionality is expected to be included in a future release. For now, I can offer the following custom code as a temporary solution. Add the code in your functions.php file to order the field groups in the View by the sort order you define in wp-admin:

add_filter( 'wpv_filter_query', 'order_rfg_by_wp_admin_sort', 199, 3 );
function order_rfg_by_wp_admin_sort( $query_args, $views_settings, $view_id) {
  $view_ids = array( 12345 );
  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);
}

Replace 12345 with the numeric ID of the View. Let me know if this does not apply the correct sorting.

#908589

Thanks. That confirms I should use this sorting: hidden link

However, it feels like the documentation both on your site and in-context (that blue info box) are missing that the "Field - toolset-post-sortorder = Ascending = As a native custom field" (or "As a number") is the only way to get them to appear in their drag-and-drop order.

That field name should be selected by default or right at the top to easily select it / suggest selecting it.
And "Descending" being the default option makes them in reverse order, which doesn't make sense either. I appreciate the flexibility to be able to display in reverse order, but it's confusing UX to just get the expected display order.
And "As a string" just doesn't work so the whole drop-down shouldn't even display (extra confusion) if toolset-post-sortorder is the selected ordering field.

Hope all that feedback is easy enough to understand. Thanks!

#908851

Okay yes, I can confirm that the Field - toolset-post-sortorder option will order by the RFG order of appearance in wp-admin. As far as the default order selection, I will refer this ticket to Beda, who handles feature requests. He will evaluate your request to improve the usability of the RFG feature and respond to you soon.

#908855

Makes sense, I added the request.

#909145

Great. Thanks!

#918116

I saw a version update come through but the changelog was vague, and I couldn't find any changelog on your site. Was this bug fixed in this latest update?

#1080244

Hello

I tried the code
---------------------
add_filter( 'wpv_filter_query', 'order_rfg_by_wp_admin_sort', 199, 3 );
function order_rfg_by_wp_admin_sort( $query_args, $views_settings, $view_id) {
$view_ids = array(369);
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);
}
----------------------------------

It does work on the view '369', but it breaks all other views 'No items found' Can you please tell me how to make it work only for the views I select?

Thanks

#1080640

miguelG-5, you must define the $args array outside the conditional like this:

add_filter( 'wpv_filter_query', 'order_rfg_by_wp_admin_sort', 199, 3 );
function order_rfg_by_wp_admin_sort( $query_args, $views_settings, $view_id) {
$view_ids = array(369);
$args = array();
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);
}

Please open a separate ticket if you continue to experience problems.

#1081102

Thank you Christian, this time it works well

#1105691

+1 for @Clifford for reporting this; I was having same issue. I see that selecting that "Field - toolset-post-sortorder : Asc : Number" works, but that's certainly not very intuitive.

I second the idea that it be renamed something more obvious (like "Repeating Group UI Order" or whatever) and not offer the string/number option at all; and default to ASC (as in the UI)