Skip Navigation

[Resolved] Output Repeater fields in their drag-and-drop order

This support ticket is created 4 years, 1 month 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
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: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 4 years, 1 month ago.

Assisted by: Jamal.

Author
Posts
#1898615

I have some custom fields which are a repeater field..

I have them displaying in a sidebar of the page via a shortcode

function green_shortcode() {
ob_start();

?>
<div class="-sidebar-green"> <div class="sidebar-green-header">
<h3>Downloads</h3>
</div>
<?php
$child_posts = toolset_get_related_posts( get_the_ID(), 'download-link', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($child_posts as $child_post)
{ ?>
<div class="sidebar-green-link sidebar-link">
<div class="image">
<img src="<?php echo types_render_field( "file-type", array( "id"=> "$child_post->ID")); ?>"></div>
<div class="link">
$child_post->ID, "output" => "raw")); ?> ">
post_title; ?>

</div></div>
<?php } ?>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'green', 'green_shortcode' );

it all shows fine, However. The order is not the same on frontend as it is on the backend..
We used the drag drop order on back end to be:

A
C
D
F
B
E

On the front end they are more like
A
B
C
D
E
F

How do we order by?

I have already looked here https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

Thanks

#1899507

Hello and thank you for contacting the Toolset support.

Can you try by settings the order for toolset_get_related_posts to 'rfg_order' as described in the documenation:

$child_posts = toolset_get_related_posts( 
    get_the_ID(), 
    'download-link', 
    array( 
        'query_by_role' => 'parent', 
        'return' => 'post_object', 
        'orderby' => 'rfg_order', 
        'order' => 'ASC' 
    )
 );