admin管理员组

文章数量:1130349

I'm using MultiLingualPress* on one of my pages, which is multisite, multilingual.

I am trying to get the permalink of a page based on two things:

1) The ml_source_elementid, which identifies the grouping of pages. (i.e. About Us (EN), Sobre Nos (PT)). This I know ahead of time. In this case it is 92.

2) The current language. This I can do by calling

mlp_get_current_blog_language(true);

I have been able to get the permalink using the WordPress general

<?php
    $url = get_the_permalink(92);
    $current_lang = mlp_get_current_blog_language(true);
    $ml_permalink = apply_filters('ml_permalink', $url , $current_lang );
    echo $ml_permalink
?>

Any idea if I can apply these sorts of filters to get the link? Or is there a better way to do this?

Thanks!!

*

I'm using MultiLingualPress* on one of my pages, which is multisite, multilingual.

I am trying to get the permalink of a page based on two things:

1) The ml_source_elementid, which identifies the grouping of pages. (i.e. About Us (EN), Sobre Nos (PT)). This I know ahead of time. In this case it is 92.

2) The current language. This I can do by calling

mlp_get_current_blog_language(true);

I have been able to get the permalink using the WordPress general

<?php
    $url = get_the_permalink(92);
    $current_lang = mlp_get_current_blog_language(true);
    $ml_permalink = apply_filters('ml_permalink', $url , $current_lang );
    echo $ml_permalink
?>

Any idea if I can apply these sorts of filters to get the link? Or is there a better way to do this?

Thanks!!

*https://multilingualpress

Share Improve this question asked Oct 31, 2018 at 16:49 Brad AhrensBrad Ahrens 1312 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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!

I'm using MultiLingualPress* on one of my pages, which is multisite, multilingual.

I am trying to get the permalink of a page based on two things:

1) The ml_source_elementid, which identifies the grouping of pages. (i.e. About Us (EN), Sobre Nos (PT)). This I know ahead of time. In this case it is 92.

2) The current language. This I can do by calling

mlp_get_current_blog_language(true);

I have been able to get the permalink using the WordPress general

<?php
    $url = get_the_permalink(92);
    $current_lang = mlp_get_current_blog_language(true);
    $ml_permalink = apply_filters('ml_permalink', $url , $current_lang );
    echo $ml_permalink
?>

Any idea if I can apply these sorts of filters to get the link? Or is there a better way to do this?

Thanks!!

*

I'm using MultiLingualPress* on one of my pages, which is multisite, multilingual.

I am trying to get the permalink of a page based on two things:

1) The ml_source_elementid, which identifies the grouping of pages. (i.e. About Us (EN), Sobre Nos (PT)). This I know ahead of time. In this case it is 92.

2) The current language. This I can do by calling

mlp_get_current_blog_language(true);

I have been able to get the permalink using the WordPress general

<?php
    $url = get_the_permalink(92);
    $current_lang = mlp_get_current_blog_language(true);
    $ml_permalink = apply_filters('ml_permalink', $url , $current_lang );
    echo $ml_permalink
?>

Any idea if I can apply these sorts of filters to get the link? Or is there a better way to do this?

Thanks!!

*https://multilingualpress

Share Improve this question asked Oct 31, 2018 at 16:49 Brad AhrensBrad Ahrens 1312 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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!

本文标签: phpHow to Get Linked Elements for a specific mlsourceelementid