Support

Account

Home Forums General Issues ACF not visible on translated pages WPML

Solved

ACF not visible on translated pages WPML

  • I’ve built a site of six pages translated into 6 languages that relies heavily on ACF. For all pages of the first language everything works fine but for the translated pages the default WordPress page is there with no sign of the custom fields.

    I’ve included acf with the theme rather than as a plugin and I thought I could go in and hardcode the location like so :

    'location' => array (
    			array (
    				array (
    					'param' => 'page',
    					'operator' => '==',
    					'value' => '8',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    				array (
    					'param' => 'page',
    					'operator' => '==',
    					'value' => '153',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    

    8 being the id of the home page and 153 the id of the home page in French.

    Any idea of how I should do this?

  • Hi @mantismamita

    I’m pretty sure that the WPML contains a function to retrieve the $post_id of the current Languages version of an ID. For example, you could change your code to:

    
    array (
    'param' => 'page',
    'operator' => '==',
    'value' => wpml_get_current_post_id(8),
    'order_no' => 0,
    'group_no' => 0,
    ),
    

    Then, the ID will become dynamic to the language you are viewing in.

    Please note that I have used a made up function, and you need to research on the WPML api to find the correct function.

    Thanks
    E

  • Hi Elliot,
    The wpml_get_current_post_id(); gave me a fatal error but I’ve contacted them as well. In the meantime I sorted it out by hardcoding the values like so:

    location' => array (
    			array (
    				array (
    					'param' => 'page',
    					'operator' => '==',
    					'value' => '8',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    			array (
    				array (
    					'param' => 'page',
    					'operator' => '==',
    					'value' => '153',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),

    (I was missing an array in the first example) Anyhow I’ll let you know which function worked when I get a response from them.

    Cheers for the quick response,
    Kirsten

  • Hi @mantismamita

    You may have missed it, but in my previous reply, I did say:

    
    Please note that I have used a made up function, and you need to research on the WPML api to find the correct function.
    
  • Sorry Elliot,
    I did miss that. The correct function in case anyone asks is icl_object_id()
    Thanks again,
    Kirsten

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

The topic ‘ACF not visible on translated pages WPML’ is closed to new replies.