Support

Account

Home Forums Front-end Issues Query relationship values with WPML

Solved

Query relationship values with WPML

  • Hello,

    i’m using ACF + WPML + relationship fields.

    On a city page, i do list different custom posts types ( like restaurants, hotels, etc… )

    In default language ( french (FR) ) everything is OK.

    i do list all those items by filtering meta with ID & LIKE.

    Classic query, based on ACF doc.

    		$args = array(
    				'post_type' => 'restaurant',
    				'posts_per_page' => -1,
    				'meta_query' => array(
    					array(
    						'key' => 'contact_city', 
    						'value' => '"' . get_the_ID() . '"',
    						'compare' => 'LIKE'
    						)
    					)
    				);		
    		$query = new WP_Query($args);
    		if ($query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
    			$title = get_the_title();
    			$permalink = get_the_permalink();
    			echo '<a href="'.$permalink.'">'.$title.'<a>';
    		endwhile;
    		endif;

    But when i change language, i do have 0 results displayed. ( posts are translated & published in other languages ).

    if i echo get_the_ID();

    i get the good ID for each language
    ( fr = 1104 / en = 1123 )

    If i change ‘value’ to 1104, i do have the correct results displayed in every language.

    So this mean that my relationship are all based on FR id. How can i manage this ? To set ID as current language ID, or to query ID from FR relationship?

    any idea ?

  • i found Advanced Custom Field Multilingual in other forum topics,
    but if i activate this plugin nothing changes, except that i can not query with 1104 as previously ^^

  • founded a solution here with getting original_id over here

    https://wpml.org/forums/topic/get-the-id-of-post-in-language-in-which-it-was-first-written/#post-130602

    but if someone have a better id !

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

The topic ‘Query relationship values with WPML’ is closed to new replies.