Skip Navigation

[Resuelto] I am not able to display custom field groups in order

This support ticket is created hace 6 años. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Christian Cox hace 6 años.

Asistido por: Christian Cox.

Autor
Mensajes
#1144255
toolst-support.JPG

Hi Toolst support team,
When editing the grupo fields on a post there is a drag and drop option to order them(or that's what it seems to be that feature for). But on the page they are displayed in the order the post where created, not the order configured with that drag and drop feature. **see screenshot no.1 to see what i mean by the drop down feature.

My code looks like this:

<?php $child_post = types_child_posts('n-h-section');
        if(!empty($n_h_sections)) :
          foreach ($n_h_sections as $n_h_section) { ?>
            <h2><?php echo get_the_title($n_h_section->ID); ?></h2> 
<?php } ?>  

'n-h-section' is the slug I asigned to the repeatable group fields.

Do I have to send types_child_posts function a specific argument to display the posts in the right order?

I am trying to:
Change the order the custom fields are displayed on the front end.

I expected to see:
The post in the right order. The right order being the one I configure when edditing the post custom fields using the drag and drop feature.

Instead, I got:
The custom fields in the order they are created.

I know you may request ftp access, My website is on Flywheel so please share with me an email that I can use to give you access.

Thanks in advance for your help.

#1144506
Screen Shot 2018-11-11 at 3.01.03 PM.png

Hi, the types_child_posts function is deprecated and we don't recommend using it. Instead, it's best to use the new post relationships APIs. Repeatable Field Groups (RFGs) are essentially child posts in a one-to-many relationship with their parent post. The relationship slug is identical to the RFG slug. The toolset_get_related_posts API is recommended for querying related posts, including RFGs:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts

$post_id = 12345; // parent post ID
$child_posts = toolset_get_related_posts(
    $post_id, // get posts related to this one
     'rfg-slug', // relationship slug is identical to repeatable field group slug
    'parent', // get posts where $post_id is the parent in given relationship
    1000000, 0, // pagination
    array(), // no extra query criteria
    'post_id', // return an array of post IDs
    'child', // return the child post, which is the RFG in this relationship
);

We also have an example showing how to add post relationship criteria to a standard WP_Query: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

In code-based queries, you should sort on the postmeta key "toolset_post_sortorder". Or you can use Views to display the RFGs. Add a post relationship filter. Choose the Order option Field: toolset_post_sortorder as shown in the attached image. Then you can insert the View using the render_view API: https://toolset.com/documentation/programmer-reference/views-api/#render_view