Support

Account

Home Forums General Issues Relationship field is returning all the same link

Solved

Relationship field is returning all the same link

  • I’m using a relationship field for linking to related recipes (so my client can choose). The number of items it returns is correct, but they are all the same link.

    eg.:
    Post Link 1
    Post Link 1
    Post Link 1

    When it should be:
    Post Link 1
    Post Link 2
    Post Link 3

    This is what I’m using to display the links chosen:

    <?php $relatedposts = get_field('recipe_related_recipes'); ?>
        <?php if( $relatedposts ): ?>
            <ul class="side-menu side-menu-last">
            <?php foreach( $relatedposts as $relatedpost ): ?>
                <li><a href="<?php echo get_permalink( $relatedpost->ID ); ?>" target="blank"><?php echo get_the_title( $relatedpost->ID ); ?></a></li>
            <?php endforeach; ?>
            </ul>
        <?php endif; ?>
  • try to return just post ID

  • maybe you already set the field to return just post_id instead of post object? so wp showing current post titles and links

    (copyed your code to my site with relationship field and all works fine)

  • Thank you! I figured out I had to change it to “Post Link” instead of relationship

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

You must be logged in to reply to this topic.