I'm trying to echo out images and custom fields, however, I think I'm not properly connecting the ID with the variable fields. I'm using blog posts with Advanced Custom Fields in WordPress. I want the same effect as a repeater, but because it's not in a repeater, I'm not using the standard if/while statements.
I'm not well versed in PHP in regards to using with WordPress, but I've already tried to assign IDs to each custom field.
$englishBio = get_field('english_bio', $post->ID);
I've also tried (which might actually be the same thing)
$id = $post->ID
$englishBio = get_field('english_bio', $id);
Here's what the image looks like:
I've seen a few examples like the following (I'm looking for the same idea, but I can't simply hardcode the post ID numbers. I need to pull the ID from the image associated with its ID):
<p><?php the_field('field_name', 123); ?></p>
<!--Pull Events category from posts-->
<?php $args = array('post_type' => 'post', 'field'=> 'ID', 'category_name'=> 'portraits', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'posts_per_page' => -1);
$catquery = new WP_Query( $args ); ?>
<?php while($catquery->have_posts()) : $catquery->the_post();
//Convert to variables
$id = $post->ID;
$name = get_the_title();
$englishBio = get_field('english_bio');
$spanishBio = get_field('spanish_bio');
$image = get_field('image');
?>
<div class="photo">
<?php echo $image ? '<img src="'. $image['url'] .'" alt="'. $image['alt'] .'" title="'. $image['title'] .'" />' : ''; ?>
<?php echo $name ? '<h2>'. $name .'</h2>' : ''; ?>
<?php echo $englishBio ? $englishBio : ''; ?>
<?php echo $spanishBio ? $spanishBio : ''; ?>
<?php echo $id; ?>
</div>
<?php endwhile; ?>
The end echoing of the ID is to just see if the post id numbers are displaying, which they are, and yes, they are correct, however, the image, English content, and Spanish content are not displaying at all, even if I do something like:
$englishBio = get_field('english_bio', $post->ID);