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++;
}
}
?>
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.
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.
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++;
}
}
?>