If I understand you right, you have a related “addon” (one post of type “addon”) on this post through “add_on_suites” field.
If that’s correct, then you just need to check in every iteration which is the needed “addon” by adding a comparison operation like this: $related_addon_id == $addon->ID
Here is the code:
<?php $addons = get_posts(array( 'post_type' => 'addons', 'posts_per_page' => -1 )); ?> <?php if( $addons ): $related_addon_id = get_field('add_ons_suites'); ?> <table class="table table-hover table-sm inclusions"> <thead> <tr> <th colspan="2" scope="colgroup" class="text-uppercase">Product Inclusion</th> </tr> </thead> <tbody> <?php foreach( $addons as $addon ): ?> <tr> <td> <a href="<?php echo get_permalink( $addon->ID ); ?>"> <i class="fas fa-chevron-right mr-1"></i><?php echo get_the_title( $addon->ID ); ?></a> </td> <td> <?php if( $related_addon_id == $addon->ID ): ?><i class="fas fa-check"></i> <?php else: ?> <i class="fas fa-times"></i> <?php endif; ?> </td> </tr> <?php endforeach; ?> </tbody> </table> <?php endif; ?>
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've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.