I have two custom fields in ACF for WYSIWYG content, named left_content and right_content. My goal is to verify if either of these fields has images and then to apply a CSS class called image_present if any do.
The issue I’m facing is that my current implementation detects images across both fields. For instance, if I upload an image exclusively to the right content field, it still appears in both the left and right columns on the website, creating duplicates.
Here’s the code I am using:
if(get_sub_field('left_content')){
if(get_sub_field('left_content', $attachment['ID'])) {
$left_area.= '<div class="column left_area image_present">'.wpautop(apply_filters('the_content',get_sub_field('left_content'))).'</div>';
} else {
$left_area.= '<div class="column left_area">'.wpautop(apply_filters('the_content',get_sub_field('left_content'))).'</div>';
}
}
if(get_sub_field('right_content')){
if(get_sub_field('right_content', $attachment['ID'])) {
$right_area.= '<div class="column right_area image_present">'.wpautop(apply_filters('the_content',get_sub_field('right_content'))).'</div>';
} else {
$right_area.= '<div class="column right_area">'.wpautop(apply_filters('the_content',get_sub_field('right_content'))).'</div>';
}
}
I had hoped that this would isolate the image detection for each field, but it’s currently not functioning as expected. When I add images to the right content field only, both columns end up displaying the same images. How can I ensure that the image detection only pertains to the specific field where the image is uploaded?