Skip to content

Get translations when calling Wordpress Rest API #232

Description

@lucky-yoolk

hi,

first thanks for your awesome plugin! Saves me a lot of time when i have to manage Multilingual websites.

Is there a way to register translations when calling Wordpress Rest API?

Below is my attempt at doing something beyond my expertise ^^

/* https://domain.com/en/wp-json/wp/v2/post/id */
function register_mls_for_rest_api() {
	register_rest_field( 
		'post',
		'mls_translations',
		array(
			'get_callback'    => 'get_mls_translations',
			'update_callback' => null,
			'schema'          => null,
		)
	);
}
add_action( 'rest_api_init', 'register_mls_for_rest_api' );

function get_mls_translations() $object, $field_name, $request ) {
	// this is where i'm stuck...
	// $lang_array 		= where_im_stuck('-_-');
	// $hreflang 		= $lang_array['0'];
	// $href 		= $lang_array['1'];
	// return array(
	// 	$hreflang => $href,
	// );
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions