Thanks, John, for your help. I appreciate it!
It turns out that having HTML code in the checkbox field itself is not a good idea. When using the field, the selections don’t stick (i.e. the selected options are gone the next time you edit the post).
So I went with only plain text values for the checkbox field and coded everything else in the template. Unfortunately, I read your sample code too late – going with “switch” would have been a good idea. As I’m not experienced with PHP, I handcrafted this subpar solution:
$tools_choices = get_field('tools'); if( $tools_choices ): ?> <h3 class="acf-title">Tools</h3> <?php foreach( $tools_choices as $name ): ?> <?php if( $name == 'Tool1' ): ?> <a href="https://url1.com/" target="_blank"><i class="fab fa-icon-x"></i><?php echo $name; ?></a> <?php elseif( $name == 'Tool2' ): ?> <a href="https://url2.com/" target="_blank"><i class="fab fa-icon-y"></i><?php echo $name; ?></a> <?php elseif( $name == 'Tool3' ): ?> <a href="https://url3.com/" target="_blank"><i class="fab fa-icon-z"></i><?php echo $name; ?></a> <?php else: ?> <p><i class="fab fa-icon-a"></i><?php echo $name; ?></p> <?php endif; ?> <?php endforeach; ?> <?php endif; ?>
It’s not the best code, but it works. If I later have the time and energy, I might change my code to a cleaner version based on your input.
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!
📣 “ACF Chat Fridays”— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.