Last active
October 24, 2017 13:28
-
-
Save rutger1140/85b5c094f95944b21216 to your computer and use it in GitHub Desktop.
Get link to other language for post in MultilingualPress (MLP) WordPress plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Usage | |
// $linked = lwp_get_language_link($siteid, $postid); | |
// $link = $linked['link']; | |
// $title = $linked['title']; | |
// Return | |
// array['link'] for link to post | |
// array['title'] title of post | |
function lwp_get_language_link($original_site_id, $original_content_id){ | |
$mlp_language_api = apply_filters( 'mlp_language_api', NULL ); | |
if ( ! is_a( $mlp_language_api, 'Mlp_Language_Api_Interface' ) ) | |
return; | |
$args = array ( | |
'strict' => TRUE, | |
'include_base' => TRUE, | |
'site_id' => $original_site_id, | |
'content_id' => $original_content_id | |
); | |
$translations = $mlp_language_api->get_translations( $args ); | |
$linked_post = array(); | |
// Loop through translations | |
foreach ($translations as $translation) { | |
// Return link and title for current translation | |
if ( $translation->get_target_site_id() == get_current_blog_id() ){ | |
$linked_post['link'] = $translation->get_remote_url(); | |
$linked_post['title'] = $translation->get_target_title(); | |
} | |
} | |
return $linked_post; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment