I am trying to:
Reorder entries in a repeatable field group.
I have a repeatable field group on a post. I just added two new entries, and want them to appear on top. I changed the order in the admin area, but they appear below the new entries on the front end.
I've uploaded to images, but they are not uploading properly. I'll try again to make it clear.
This is my code in my template:
<?php
$child_posts = toolset_get_related_posts( get_the_ID(), 'community-programs', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($child_posts as $child_post) { ?>
<li>
<a target="blank" rel="noopener" href="<?php echo (types_render_field( 'program-news-url', array( "id"=> "$child_post->ID" ) ) );?>">
<?php echo (types_render_field('program-or-news' , array( "id"=> "$child_post->ID" ) ) ); ?></a>
</li>
<?php } ?>
Hi, RFG have a meta value "toolset-post-sortorder" that is used to determine sorting. You could add that meta_key to your toolset_get_related_posts query along with meta_compare, and use meta_value_num in the order argument:
$child_posts = toolset_get_related_posts(
get_the_ID(),
'community-programs',
array(
'query_by_role' => 'parent',
'args' => array(
'meta_key' => 'toolset-post-sortorder',
'meta_compare' => 'EXISTS'
),
'orderby' => 'meta_value_num',
'order' => 'ASC',
'return' => 'post_object'
)
);
Thank you for that code it did work. But it doesn't change the order on a page translated by WPML. Is there anything I have to do? I'm translating manually, not with the translate tool because of conflicts elsewhere on my site.
Thank you for that code it did work. But it doesn't change the order on a page translated by WPML.
Which page are you referring to, the translated Community post, or some other post?
Please go to WPML > Settings > Multilingual Content Setup.
Scroll down to Custom field settings. What is the translation setting for toolset-post-sortorder?
Scroll down to the Post Types Translation section. What are the translation settings for the Community post type?