Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress get\u post\u meta()返回空_Wordpress_Translation_Shortcode - Fatal编程技术网

Wordpress get\u post\u meta()返回空

Wordpress get\u post\u meta()返回空,wordpress,translation,shortcode,Wordpress,Translation,Shortcode,我正在为翻译wordpress站点页脚中的文本做一个基本的短代码,我正在使用get_post_meta()来标识meta标记中的语言(我正在添加一个插件,用于在页眉中插入html代码),但它返回空的。我想知道这是否是因为插件和他创建元素的顺序(首先他执行我的短代码,然后是插件)或者如果它是其他东西 function text_Footer($atts, $content=null){ extract(shortcode_atts(array( 'id' =&g

我正在为翻译wordpress站点页脚中的文本做一个基本的短代码,我正在使用get_post_meta()来标识meta标记中的语言(我正在添加一个插件,用于在页眉中插入html代码),但它返回空的。我想知道这是否是因为插件和他创建元素的顺序(首先他执行我的短代码,然后是插件)或者如果它是其他东西

function text_Footer($atts, $content=null){ 

    extract(shortcode_atts(array(
            'id' => ''
    ), $atts));
    $ID = get_the_ID();
     $lang = get_post_meta(ID,'language',true);
    if($lang == 'portuguese')
    {
    $output='<p>Text in portuguese</p>';
    }
    else
    {
    //echo $lang."nope";
    $output = '<p>Text in spanish</p>';
    }
    return $output;
}
函数文本\u页脚($atts,$content=null){
提取(短码)附件(数组)(
'id'=>'
)美元(附件);;
$ID=get_the_ID();
$lang=get\u post\u meta(ID,'language',true);
如果($lang==“葡萄牙语”)
{
$output='葡萄牙语文本

'; } 其他的 { //echo$lang“不”; $output='西班牙语文本

'; } 返回$output; }
get\u函数必须在循环中。
如果你想从短代码中提取id,只需要以写的方式使用它:
$lang=get_post_meta($id,'language',true);

这里没有什么问题,比如
get_post_meta(id,'language',true);
,不要使用
extract
,也不清楚你试图在这里指向哪个post对象。