Skip Navigation

[Resolved] Repeating Group Fields in a template file

This support ticket is created 4 years, 12 months 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by CraigS3893 4 years, 12 months ago.

Assisted by: Minesh.

Author
Posts
#1238549

Hi
I'm trying to output a repeating group of fields in a page template. I'm attempting to allow the client to add multiple rows to their page, in three types (regular, image, two column) - these are selectable by radio button in the custom fields. I've tried the following but it's returning nothing, can you help?

<?php
$child_posts = toolset_get_related_posts( get_the_ID(), 'page-content', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($child_posts as $child_post)
{ ?>

<?php $paneltype = types_render_field("panel-type", array("raw"=>"true"));
if ($paneltype == 'regular') {
// Show Regular Panel ?>

<?php echo types_render_field( "panel-title", array( "id" => "$child_post->ID" )); ?>
<?php echo types_render_field( "panel-content", array( "id" => "$child_post->ID" )); ?>

<?php } elseif ($paneltype == 'image') {
// Show Image Panel ?>

<?php echo types_render_field( "panel-image", array( "id" => "$child_post->ID" )); ?>

<?php } elseif ($paneltype == 'two-column') {
// Show Two Column Panel ?>

<?php echo types_render_field( "panel-left", array( "id" => "$child_post->ID" )); ?>
<?php echo types_render_field( "panel-right", array( "id" => "$child_post->ID" )); ?>

<?php } else {
// Show Nothing ?>

<?php }?>

<?php }?>

#1238559

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - can you please share problem URL and access details as well as path to your PHP tempalte file where you added the above code.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1238562

Hi, the site is in development on my local machine. It isn't available online yet.

#1238565

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - can you share screenshot of your repeatable field group (please take screenshot so that I can see all fields configurations) as well as one screenshot of edit post screen where this repeating field group is displayed?

Based on that I will try to share solution.

#1238579
types-repeating-group.png
types-edit-page.png
Screen Shot 2019-05-02 at 11.35.39.png

Hi, thanks. Screenshots attached.

#1238593

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok great - thank you.

Can you do one thing, go to: Toolset => Export / Import
- on Types tab export the Types data and send me that file.

Please upload that file to google drive and share the link to download it.

I have set the next reply to private which means only you and I have access to it.

#1238596

hidden link

#1238608

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing all informationn.

Well - Please try to use the following code:

There were couple of issues, you were passing id argument to types_render_field() function as "$child_post->ID" but it should be passed without quotes $child_post->ID.

I fixed all those little things and please try to use the following code and confirm it works as expected.

$child_posts = toolset_get_related_posts(
    get_the_ID(),
    'page-content',
    'parent',
    1000,
    0,
    array(),
    'post_object',
    'child');
	
	

foreach ($child_posts as $child_post){


$paneltype = types_render_field("panel-type", array("raw"=>"true",'id'=>$child_post->ID));

if ($paneltype == 'regular') {

// Show Regular Panel
 echo types_render_field( "panel-title", array( "id" => $child_post->ID )); 
 echo types_render_field( "panel-content", array( "id" => $child_post->ID )); 
 
 } elseif ($paneltype == 'image') {

 // Show Image Panel 

 echo types_render_field( "panel-image", array( "id" => $child_post->ID ));

 } elseif ($paneltype == 'two-column') {
// Show Two Column Panel 

 echo types_render_field( "panel-left", array( "id" => $child_post->ID )); 
 echo types_render_field( "panel-right", array( "id" => $child_post->ID )); 

} else {
// Show Nothing 

}

}
#1238609

It's okay, I got it working. I'd missed out passing ("id" => "$child_post->ID") to the $paneltype variable.

For the record, the full code with layout HTML is below.

<?php
$child_posts = toolset_get_related_posts( get_the_ID(), 'page-content', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($child_posts as $child_post)
{ ?>

<?php $paneltype = types_render_field("panel-type", array("id" => "$child_post->ID"));
if ($paneltype == 'regular') {
// Show Regular Panel ?>

<div style="background: <?php echo types_render_field( "panel-colour", array( "id" => "$child_post->ID", "raw" => "true" )); ?>">
<div class="row">
<div class="content-regular">
<h2><?php echo types_render_field( "panel-title", array( "id" => "$child_post->ID" )); ?></h2>
<?php echo types_render_field( "panel-content", array( "id" => "$child_post->ID" )); ?>
</div>
</div>
</div>

<?php } elseif ($paneltype == 'image') {
// Show Image Panel ?>

<div class="content-image" style="background-image: url(<?php echo types_render_field( "panel-image", array( "id" => "$child_post->ID", "raw" => "true" )); ?>);">
<div class="row">
<div class="small-12 columns">
<h2><?php echo types_render_field( "panel-title", array( "id" => "$child_post->ID" )); ?></h2>
<?php echo types_render_field( "panel-content", array( "id" => "$child_post->ID" )); ?>
</div>
</div>

</div>

<?php } elseif ($paneltype == 'two-column') {
// Show Two Column Panel ?>

<div class="row">
<div class="small-12 medium-6 columns">
<?php echo types_render_field( "panel-left", array( "id" => "$child_post->ID" )); ?>
</div>
<div class="small-12 medium-6 columns">
<?php echo types_render_field( "panel-right", array( "id" => "$child_post->ID" )); ?>
</div>
</div>

<?php } else {
// Show Nothing ?>

<?php }?>

<?php }?>
<?php wp_reset_query(); ?>

#1238610

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.