Skip Navigation

[Resolved] cannot add repeating field item

This support ticket is created 8 years, 4 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.

This topic contains 3 replies, has 1 voice.

Last updated by McElhinney 8 years, 4 months ago.

Author
Posts
#345586

I have a repeating field set up for my homepage, each field is a simple image for a slideshow banner. When I am editing the homepage I can add and delete banners fine, but on the front end only deletions are shown, it does not recognise that I add new items. It seems to occur when I select an existing image from the media gallery, rather than upload a new image. The front end code basically goes like this:

<?php

   $args = array(
	'post_type' => 'attachment',
	'post_parent' => $post->ID,
	'orderby' => 'menu_order',
	'order' => 'ASC'
	);
?>


<?php	
$attachments = get_posts($args);
if ($attachments) {
	$i=0;
	    foreach ($attachments as $attachment) { //outputs the banner images which have been uploaded on the 'home' page entry
	    echo '<div class="'; 
		if($i == 0) {echo 'active ';} //applies active class to first item only
		echo 'item">'.wp_get_attachment_image( $attachment->ID, 'homepage-banner', '', array('alt' => $attachment->post_title));
		echo '</div>';

        $i++;		
	    }
	}	
?>
#345592
homepage-banners.jpg

on further investigation it seems that the images aren't being attached to the homepage in the media, despite the new fields being saved in the homepage. Please see the screenshots. There are 4 slideshow images but only 3 of them have actually been attached to the homepage.

#345594

image 102 seems to be attached to another page (gallery) so I'm not sure if this is why it's occuring, because I've selected this image to use in the homepage banner.

#345639

fixed myself by using this code inside the wordpress post loop:

<?php	

$attachments = types_render_field('home-banner-img', array("url" => "true", "size" => "homepage-banner" ));
$attachments = explode(" ",$attachments);// change the string output to an array

if ($attachments) {
	$i=0;
	    foreach ($attachments as $attachment ) { //outputs the banner images which have been uploaded on the 'home' page entry
	    echo '<div class="'; 
		if($i == 0) {echo 'active ';} //applies active class to first item only
		echo 'item">';
		echo '<img src="'.$attachment.'">';
		echo '</div>';

        $i++;		
	    }
	}	
?>

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.