Home Forums General Issues Relationship field acting weird


Relationship field acting weird

  • Hi all,

    I am facing some strange situation, and I don’t know where the problem might lie.

    I have created a relationship field for my homepage. The idea is to use it to display some featured pages. When I paste the following code in my homepage.php template, in the frontend it displays the title of the homepage, instead of the title of the related page. It does not retrieve the second custom field:

    <?php $posts = get_field(‘productos_destacados’);

    if( $posts ):

    foreach ( $posts as $post ) :

    setup_postdata($post); ?>

    <?php the_title(); ?><?php the_field(‘titulo_programa’); ?>

    <?php endforeach;


    endif; ?>

    The interesting part is the following: If I use the relationship field to link one page, the code displays the title of the frontpage one time. If I link two pages, the title of the frontpage is displayed two times, three pages, three times, and so on.

    It seems to be somehow reading the relationship field, seeing how many pages it contains, but it cannot retrieve any field from the linked pages.

    Does anyone have any idea of what the problem could be? How could I solve it?

    Thanks in advance!

  • I created a part template and pasted the code there instead. It worked. I guess there must be a compatibility problem within the front page, but I don’t see what it could be.

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

The topic ‘Relationship field acting weird’ is closed to new replies.