How to Get Linked Elements for a specific ml_source_elementid

So, I made a word around, which works, but may not be best practice, particularly if there are premade functions for this particular situation, which there must be.

Anyway, I did a simple SQL search within the wp_multilingual_linked table for the ml_source_elementid that I wanted to have the links from. Then, as I have defined the blog_id based on language, I was able to get the link via the get_the_parmalink WordPress built-in function.

Setup the languages:

<?php
    $language = mlp_get_current_blog_language(true);
    switch($language) {
        case "en": $blog_id = 1; break;
        case "pt": $blog_id = 2; break;
        case "it": $blog_id = 3; break;
    }
?>

Search for the permalinks based on their source element id:

<?php
    global $wpdb;
    $result = $wpdb->get_results("SELECT * FROM wp_multilingual_linked WHERE ml_source_elementid = '92' and ml_blogid = $blog_id");
    echo get_the_permalink($result->ml_elementid);
?>
  • Note that 92 was my particular source_elementid that I had to find in the wp_multilingual_linked table within SQL. This will more than likely be different for you if you are trying this.

This works, but it probably isn’t the most efficient way to get there. Does anyone else have any ideas?

Thanks!