Skip Navigation

[Resolved] Repetable group order

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

Problem:

The customer reported that repeating field groups are not returned in the order they're set in the admin area when used in the PHP code.

Solution:

The PHP code was using the "toolset_get_related_posts" function to get the related repeating field group items.

Suggested to set the 'orderby' attribute to 'rfg_order' in the "toolset_get_related_posts" function.

Relevant Documentation:

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

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by davideE-4 1 year, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2409007

Hi,
I have created repetable groups. Using a function in functions.php I go to load all the single groups inserted in a post with the function
$single = types_render_field ("field-name", array ("id" => "$ icon-> ID", "output" => "raw", "show_name" => "false"));

However, I note that the order is incorrect. If I set an order in my post group then it's not the same as I see from the function. How come?

Regards

#2409141

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

The "types_render_field" function only calls the individual field from a repeatable field group ( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/ ) and it doesn't control the calling of the repeatable field group entries.

Around the code that you've shared, you must be using some other function to query all the repeatable field group entries, which technically are separate post entries.

The Toolset Types manages the order of the repeatable field group entries/posts, with respect to a custom field "toolset-post-sortorder". You can update your function that is querying these repeatable field group entries/posts to order by this custom field and the results will show in the same order as they're in the admin area.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2409145

Hi Wagar, correct.
First I call the field and then I go to see all the values. But how do I get them in the correct order? I attach to the procedure I use

$single = types_render_field ("field-name", array ("id" => "$ icon-> ID", "output " => "grezzo", "show_name" => "falso"));        
foreach ($single as $value) 
{
	$url_icona = types_render_field("url_icona", array("id"=> "$value->ID","output"=>"raw", "show_name"=>"false"));
	$label = types_render_field("icona", array("id"=> "$value->ID","output"=>"raw", "show_name"=>"false"));
}

Regards

#2409161

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

Seeing this code, I have some doubts about the setup of the fields that you're using.

Can you please share temporary admin login details, along with a link to an example page where the output of this code can be seen?

I'll be in a better position to suggest some code adjustments, accordingly.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

#2409251

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the access details.

I had to temporarily enable the WordPress file editor for the theme and plugin files from the "SiteGround Security" plugin's settings, to find the code for the dashboard creation.
( it is deactivated now )

I noticed that the code is using the "toolset_get_related_posts" function to get the related repeating field group items:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

In your plugin's file at line# 147, you have this:


$icone = toolset_get_related_posts( $post_id, 'icona-pulsate', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );

To order these results, based on the order of the repeating field group items in the admin area, you can set the 'orderby' attribute to 'rfg_order' in the function, like this:


$icone = toolset_get_related_posts( $post_id, 'icona-pulsate', array( 'query_by_role' => 'parent', 'return' => 'post_object', 'orderby' => 'rfg_order', 'order' => 'ASC' ) );

Note: This works on my test website, but your website also has the "Post Types Order" plugin active. This plugin can override the order of posts in all queries, so in case the suggested change doesn't work, try disabling the "Auto Sort" option in that plugin's settings.

#2409299

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.