Skip Navigation

[Résolu] Ordering repeatable field group custom fields by Toolset sort order not working

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 Il y a 5 années et 7 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par kasiaG Il y a 5 années et 7 mois.

Assisté par: Minesh.

Auteur
Publications
#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

Les langues: Anglais (English )

Fuseau horaire: 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.