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 badges1 Answer
Reset to default 0So, 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 badges1 Answer
Reset to default 0So, 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
版权声明:本文标题:php - How to Get Linked Elements for a specific ml_source_elementid 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749212108a2333539.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论