Home Forums Backend Issues (wp-admin) Get custom field from relation


Get custom field from relation

  • Hi

    I was able to display related posts via the advanced custom fields page.
    But I wonder how I can show a custom field value from that related post?

    Here is my code on how I am trying to add a class from a custom field from a post that is related to a different post.

    I am trying to load the equipment-kind custom field that is linked to a post that is related to the main where I show this data.

    <?php $equipments = get_field('diabetic_equipment_copy'); ?>
    <?php if( $equipments ): ?><span><strong>Diabetic Equipment:</strong></span>
        <ul class="list-diabetic-equipment">
            <?php foreach( $equipments as $equipment ): ?>
            <li class="item-diabetic-equipment"><i class="fas fa--<?php the_field('equipment-kind', $equipment->ID); ?>"></i>
            <a href="<?php echo get_permalink($equipment->ID); ?>" title="<?php echo __('Read more about') . ' ' . $equipment->post_title; ?>">
                <?php echo $equipment->post_title; ?></a>
        <?php endforeach; ?>
    <?php endif; ?>

    Thank you very much for the help.

  • I fixed it. I made a mistake in the naming of my field. Switched label and field name. Oops!

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Get custom field from relation’ is closed to new replies.