Skip Navigation

[Resolved] Ordering repeatable field group custom fields by Toolset sort order not working

This thread is resolved. Here is a description of the problem and solution.

Problem:
Ordering repeatable field group custom fields by Toolset sort order not working

Solution:
You should use the Toolset post relationship API fuunction toolset_get_related_posts() to display the repeating field entrines in specific order either ASC or DESC.

You can find the proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/ordering-repeatable-field-group-custom-fields-by-toolset-sort-order-not-working/#post-1241342

Relevant Documentation:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

This support ticket is created 5 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by kasiaG 5 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1241331
Screen Shot 2019-05-08 at 11.50.00 PM.png
Screen Shot 2019-05-08 at 11.47.40 PM.png

I am trying to get a list of buy links to output according to the sorted order on the post, and not by the order in which they were added to the post. Here is my code:

$buy_links = toolset_get_related_posts( 
  get_the_ID(), 
  'buy-links', 
  array( 
    'query_by_role' => 'parent',
    'return' => 'post_object',
    'orderby' => 'toolset-post-sortorder',
    'order' => 'ASC' ) );

What am I doing wrong? It is still outputting them in the order I added them and not my sorted order. I've attached screenshots to help illustrate the issue.

#1241342

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - can you please try to use the following code and try to resolve your issue:

$buy_links  = toolset_get_related_posts(
 get_the_ID(),     // the parent post
'buy-links',   // the RFG slug
'parent',     // the RFG role in this relationship is 'child'
100,     // the maximum number of results
0,           // the offset
array('meta_key'=>'toolset-post-sortorder'),     // additional query arguments
'post_object',   // return format
'child',    // role to return
'meta_value_num',
'ASC'
);

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

#1241345

Worked perfectly. Thank you very much.