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
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
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
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.
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.
My issue is resolved now. Thank you!