wp-graphql-polylang icon indicating copy to clipboard operation
wp-graphql-polylang copied to clipboard

Expose all translations strings

Open esamattis opened this issue 5 years ago • 0 comments

This could work

function get_polylang_strings($slug = 'en') {
	$values 		= [];
    $term           = get_term_by( 'slug' , $slug , 'language' ); 
    $posts          = get_posts(array( 'name' => 'polylang_mo_'.$term->term_id , 'post_type' => 'polylang_mo' , 'post_status' => 'private' , 'posts_per_page' =>1 ));
    $post_id        = $posts[0]->ID;
    $translations   = get_post_meta( $post_id , '_pll_strings_translations' , true );
    if(!$translations) {
    	return;
    }
    foreach($translations as $translation) {
    	$values[$translation[0]] = $translation[1];
    }
    return $values;
}

See

https://wp-graphql.slack.com/archives/CH3E1FZHB/p1580230496018300

esamattis avatar Jan 28 '20 17:01 esamattis