Your latest snippet returns this:
$first_row_image = http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh.jpg
So, this
<?php
$rows = get_field('gallery' ); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['gallery_photo' ]; // get the sub field value
?>
<img src="<?php echo $first_row_image; ?>" />
Made the image show up. Unless I’ve done something wrong here that could have been configured better, I’m calling this one done.
If you meant replace this entire block:
<?php
$rows = get_field('gallery' ); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['gallery_photo' ]; // get the sub field value
// Note
// $first_row_image = 123 (image ID)
$image = wp_get_attachment_image_src( $first_row_image, 'full' );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img src="<?php echo $image[0]; ?>" alt="why isn't this working?" />
with this:
<?php
$rows = get_field('gallery' ); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['gallery_photo' ]; // get the sub field value
$rows = get_field('gallery' ); // get all the rows
$first_row = $rows[0]; // get the first row
?>
<img src="<?php $first_row['gallery_photo' ]; ?>" alt="is this working yet?" />
then…no, still not working. The return value of the field is set to URL, but it returns <img src="" alt="is this working yet?" />
The field group is inside the loop; it’s in a single template for a custom post type. It’s also inside an if/else statement that returns either a single photo or a gallery, if there is one. As I said, everything else is working (apparently) flawlessly.
This is the context:
<?php
if ( get_field('gallery')) { ?>
<div class="gallery">
<div id="imageview">
<?php
$rows = get_field('gallery' ); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['gallery_photo' ]; // get the sub field value
// Note
// $first_row_image = 123 (image ID)
$image = wp_get_attachment_image_src( $first_row_image, 'full' );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img src="<?php echo $image[0]; ?>" alt="why isn't this working?" />
</div>
<div id="thumbnails">
<?php if( have_rows('gallery') ): ?>
<?php while ( have_rows('gallery') ) : the_row(); ?>
<a href="<?php the_sub_field('gallery_photo'); ?>"><img src="<?php the_sub_field('gallery_photo'); ?>" alt="" /></a>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php } else { ?>
<div class="listingPhoto">
<img src="<?php the_field('listing_photo'); ?>" />
</div>
<?php }
?>
…and this is what’s being returned:
<div class="gallery">
<div id="imageview">
<img src="" alt="why isn't this working?" />
</div>
<div id="thumbnails">
<a href="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh.jpg"><img src="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh.jpg" alt="" /></a>
<a href="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh4.jpg"><img src="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh4.jpg" alt="" /></a>
<a href="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh5.jpg"><img src="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh5.jpg" alt="" /></a>
<a href="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh3.jpg"><img src="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh3.jpg" alt="" /></a>
<a href="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh2.jpg"><img src="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh2.jpg" alt="" /></a>
<a href="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh7.jpg"><img src="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh7.jpg" alt="" /></a>
<a href="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh6.jpg"><img src="http://stevedowty.com/sunshine/wp-content/uploads/2017/03/mh6.jpg" alt="" /></a>
</div>
</div>
The URL is http://stevedowty.com/sunshine/listings/518-crestview-drive/
Actually, it turned out to be pretty simple. I just replaced the first code with this:
<div id="mainPhoto" style="background-image: url(<?php the_field('background_image'); ?>);">
<div id="pageTitle">
<?php the_field('page_title'); ?>
</div>
</div>
I’ve tried something like this before, and it didn’t work. This time it did. The first bit of code was copied/adapted from a previous project (where it works) because trying it this way didn’t work in the previous project.
James —
I found the problem; it was in the template.
I was using the generic WordPress function for calling the value of custom fields, which apparently works with just about everything but the wysiwyg editor. I employed this form:
<?php echo get_post_meta($post->ID, 'text', true); ?>
instead of
<?php the_field('text'); ?>
Once I changed it, everything worked fine.
So always assume an ID 10t error when something like this occurs. Thanks for all your help; sorry to have been a time-waster.
James —
I don’t know what you mean by “staging site.” The URL I gave you is to a private development site that contains nothing proprietary or confidential, and I can give you an admin login to it. Is that what you mean?
Update the Second —
I take it all back. The rendered display looked okay…but checking the page source reveals that the paragraph tags are still missing.
Update —
I copied over the wysiwyg.php template to Twenty Fifteen, and activated that theme…and the problem went away. So it apparently isn’t a custom function, since there isn’t one, but one that exists in Twenty Fifteen that doesn’t exist in the custom theme. Do you have any insight into what that might be?
James —
The function.php file is blank. I deactivated every other plugin, and the problem persists.
James —
I set up a page that replicates the problem and explains it at the same time. You can access it here.
Thanks for you help…
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.