Hello,
I have a Gallery ACF with images
Each image have a “category” from a “choice field”
My “choice field” , look like this :
choice_1 : Choice 1
…
Under each photo I want to see “Choice 1” and not “choice_1”
I tried that :
<?php the_field(‘category’, $image[‘ID’]); ?> : choice_1
<?php the_field(‘category’, $image[‘label’]); ?> : doesn’t work
How can I do it ?
Thanks a lot
Can you supply some code an a better explanation of what you are trying to do. I don’t understand based on what you’ve given.
Hello,
Sorry for my English and my code 🙂
This page is an ACF image gallery.
Each image has a “custom field” which corresponds to one of the “multiple choices” of the “custom field”: “essays”
The “multiple choice” in wordpress is in this form:
choice_1 : Choice 1
choice_2 : Choice 2
…
There are “checkboxes” at the top of the page that allow you to show or hide groups of images with the same choice.
Then under each image there is his “choice” which is displayed.
But strangely <?php the_field(‘essays’, $image[‘ID’]); ?> this code displays: “choice_1”
I would like it to display “Choice 1” (it will be different for each image group)
Thanks a lot
Here is the code for the page :
<script type="text/javascript">
$(document).ready(function() {
$('input[type="checkbox"]').click(function() {
var inputValue = $(this).attr("value");
$("." + inputValue).toggle();
});
$('select[type="option"]').click(function() {
var inputValue = $(this).attr("value");
$("." + inputValue).toggle();
});
});
</script>
<div class="tools">
<div class="essays">
<div class="coche">
<?php
$field2 = get_field_object('essays');
if ($field2['choices']) : ?>
<?php foreach ($field2['choices'] as $value => $label2) : ?>
<label class="lab"><input type="checkbox" checked="checked" name="colorCheckbox" value="voir-essays-<?php echo $value; ?>"><?php echo $label2; ?> </label>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="tools-player">
<div class="embed-container">
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
endwhile;
wp_reset_postdata();
?>
<?php
while (have_posts()) : the_post();
?>
</div>
</div>
<main id="primary" class="site-main">
<div id="scroll">
<div id="scroll2">
<?php
$images = get_field('gallery');
if ($images) : ?>
<div>
<?php foreach ($images as $image) : ?>
<?php $field = get_field_object('essays'); ?>
<div class="photo-bloc thumbnail-item2 voir-commissions-<?php the_field('commissions', $image['ID']); ?> voir-essays-<?php the_field('essays', $image['ID']); ?> ">
<img src="<?php echo $image['sizes']['large']; ?>" alt="<?php echo $image['alt']; ?>" />
<div class="tooltip">
<p>
<?php the_field('essays', $image['ID']); ?>
<!-- HERE I WOULD LIKE TO HAVE THE LABEL "CHOICE 1" and not "choix_1" (which is displayed instead of ID) -->
</p>
<p><?php echo $image['caption']; ?></p>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php
endwhile; // End of the loop.
?>
</div>
</div>
</div>
</main><!-- #main -->
Thanks a lot
From what I can tell it is showing the value of the field. A select field can be set to return the value, the label, or both and you must code dependent on what is being returned.
See code example https://www.advancedcustomfields.com/resources/select/
Thanks a lot !
It’s working !
$images = get_field('gallery');
if ($images) : ?>
<div>
<?php foreach ($images as $image) :
$colors = get_field( 'essays', $image['ID'] );
$value = $colors['value'];
$label = $colors['label'];
?>
<?php echo esc_attr($value); ?>
<?php echo esc_attr($label); ?>
You must be logged in to reply to this topic.
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.