0

I am trying to get the ACF checkbox to output an image when when it is checked. Here is what I have

<?php if (in_arry('The Home Depot', ("retailers"))) { echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/thehomedepot.jpg'" alt="The Home Depot"> } elseif(in_arry('True Value', ("retailers"))) { echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/truevalue.jpg'" alt="The Home Depot"> }else {

} ?>

retailers is the checkbox field and The Home Depot and True Value are the checkboxes.

Thanks in advance

2 Answers 2

1
<?php $retailers = get_field('retailers'); ?>

<?php if( in_array('The Home Depot', $retailers )): ?>
    <img src="<?php echo get_stylesheet_dirctory_url(); ?>/images/thehomedepot.jpg" alt="The Home Depot">
<?php endif; ?>

Make sure that 'The Home Depot' is the value of the checkbox though, not just the label. Output the array with print_r($retailers); so you can see what you're working with.

Sign up to request clarification or add additional context in comments.

4 Comments

here is what I get when i print out the retailers Array ([0] => The Home Depot ) When I add the code above it will not show the image for some reason any ideas?
I just noticed, in copying part of your code, there was an underscore missing in get_stylesheet_directory_url() - was that the problem?
I am not sure what is going on I added the code which looks right to me but it is not showing the image or even the div.
Perhaps try setting up so field value as 'the-home-depot' instead?
0

Here is what I came up with to get everything working if anyone needs the help.

<?php if(in_array('thd', get_field('retailers') ) ) {
            echo '<li>';
            echo '<a href="';
            echo get_field('the_home_depot_product_url');
            echo '">';
            echo '<img src="../thehomedepot.jpg" alt="The Home Depot" />';
            echo  '<h3>The Home Depot</h3>';
            echo '</a>';
            echo '</li>';
        } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.