Support

Account

Home Forums Front-end Issues Displaying a relationship field on a custom post type taxonomy page Reply To: Displaying a relationship field on a custom post type taxonomy page

  • Hi! Just wanted to update you on this. I had a programmer look at it and apparently the issue was that the $posts global variable was being overridden.

    When I searched through the code, the only places I saw that variable mentioned was in the main WordPress files, the ACF plugin, and the Event Calendar plugin (which I tried disabling and didn’t make a difference). So I’m not sure exactly what was the culprit there, but once that variable name was changed, it worked fine.

    Here’s the code that ended up working in case anyone else has a similar issue:

    <?php $store_type_posts = (array) get_field('store-type'); ?>
    <?php foreach ($store_type_posts as $store_type_post): ?>
    <?php $store_type_logo_id = get_field('store-type-logo', $store_type_post->ID) ?>
    <?php if ($store_type_logo_id) : ?>
    <?php $image = wp_get_attachment_image_src($store_type_logo_id, 'Store_Logo'); ?>
    <?php $alt_text = get_the_title($store_type_logo_id); ?>
    <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt_text; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" class="plain" />
    <?php endif ?>
    <?php endforeach ?>