Support

Account

Home Forums General Issues WPML get fields from another page

Solved

WPML get fields from another page

  • Hi there,

    Currently building a site using WPML. Each country has a different telephone and email displayed in either the header or footer. I would usually create fields for these and attached them to the home page and then use the following to retrieve the data (x being the page number of the home page:

    <?php the_field('field_name', X); ?>

    However, when using WPML an additional page is created for each language version and therefore a new page number making the above code display the incorrect information.

    Is there already a solution to this or will I need to determine the users country and then adjust the page numbering?

  • Hey!
    I just did the same for an website I am made.
    There are two solutions:

    1/ Option
    Instead of placing your fileds in the HP, you should creat an option page:
    https://www.advancedcustomfields.com/resources/options-page/
    That works just fine 🙂

    2/ Dynamic #ID based on your language
    Place this up the page in your php code :
    <?php $pageID = icl_object_id(329, 'page', false); ?>
    Change 329 by tyour HP’s ID.
    Then, to call the field use this:
    <?php the_field('MY_FIELD_NAME_HERE', $pageID); ?>

    Even if the second solution works fine, the 1st one is more convenient for the BackEnd user 🙂

  • Thanks so much for this – wasn’t aware of the options feature! Love it!

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

The topic ‘WPML get fields from another page’ is closed to new replies.