Home Forums General Issues Relationship field on translated pages


Relationship field on translated pages

  • Hi there,

    Until recently I had no problems with the ACF relationship fields and WPML. The only problem was that I could only get the English default relationship pages to appear on my duplicated language pages, but that was ok. Perhaps some update has changed it, but for some reason the ACF relations fields are no longer being displayed on my duplicated language pages (they are WPML duplicates, not independently translated pages). On the English pages they work fine, but with the same piece of code, nothing appears on the duplicated pages, although I can see in the duplicated post’s edit page that the fields have been copied correctly, and that I can see the right page is selected in the relationship selector.

    This is the piece of code I use to get the relationship fields. On the English Default language they work, on the duplicate translations I get nothing (although in the back-end they do appear).

    $previous_relationships = get_field('previous_relationships');
    	echo '';
    	foreach($previous_relationships as $previous_relationship)
    		echo '<a li href=' . get_permalink( $previous_relationship->ID ) . '>' . $previous_relationship->first_name . '</a></li><br>';
    	echo '';

    Does anyone know what is going on?

  • Hi @markkro

    Did you add the code outside of The Loop? If you did, you need to pass the post/page ID as the second parameter to the get_field() function like this:

    get_field(‘previous_relationships’, 99)

    Where “99” is the translated post/page ID where the custom field is assigned. This page should give you more idea about it:

    Could you also try to debug it like this:

    ehco "<pre>";
    var_dump( get_field('previous_relationships', false, false) );
    ehco "</pre>";

    Also, could you please share the template file of the page so I can check it out?

    If you could share the JSON or XML export file of the field group for both of the languages, that would be great too!

    Thanks 🙂

  • This reply has been marked as private.
  • This reply has been marked as private.
  • This reply has been marked as private.
  • Hi @markkro

    I’m afraid the files is not uploaded properly. For the PHP file, could you please copy and paste it here: or use a third-party online storage solution?

    Thanks 🙂

  • I found a solution myself. I don’t know why it does the trick, but for other people facing the same problem, you need to set the ACF relationship field of the translated field group to return post ID’s instead of post objects, and then you can call them like:


    $posts = get_field('relationship_field');

    if( $posts ): ?>

      <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
      <?php setup_postdata($post); ?>

    • "><?php the_title(); ?>
    • <?php endforeach; ?>

    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>

    And change relationship_field to the name of your relationship field.

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

The topic ‘Relationship field on translated pages’ is closed to new replies.