Php Wordpress通过传递get\U post\U元值来进行短码

Php Wordpress通过传递get\U post\U元值来进行短码,php,wordpress,Php,Wordpress,我正在使用iframe Wordpress插件。它需要一个语法(短代码),如: [iframe src=”http://www.youtube.com/embed/A3PDXmYoF5U“width=“100%”height=“480”] 我想在一个meta_键中获取信息,并通过do_shortcode函数传入Wordpress模板。我使用的代码如下所示: if ( get_post_meta($post->ID, 'youtube-video', true) ){ $youtube_

我正在使用iframe Wordpress插件。它需要一个语法(短代码),如: [iframe src=”http://www.youtube.com/embed/A3PDXmYoF5U“width=“100%”height=“480”]

我想在一个meta_键中获取信息,并通过do_shortcode函数传入Wordpress模板。我使用的代码如下所示:

if ( get_post_meta($post->ID, 'youtube-video', true) ){
  $youtube_video = get_post_meta($post->ID, 'youtube-video', true);
  echo do_shortcode('[iframe src="' . $youtube_video . '" width="100%" height="480"]');
}
但它不起作用。我认为问题在于返回值的get_post_元函数。如何解决这个问题

编辑:请注意,如果我以这种方式修改上述代码:

if ( get_post_meta($post->ID, 'youtube-video', true) ){
  $youtube_video = get_post_meta($post->ID, 'youtube-video', true);
  echo $youtube_video;
  echo do_shortcode('[iframe src="' . $youtube_video . '" width="100%" height="480"]');
}

它会打印url(),但最后一个回显不会打印任何内容。

什么是不工作?您的代码不执行或回显空字符串?如果你的条件没有执行?另外,您将此代码段称为何处?您的代码在本地安装+Twenty12上运行良好。如果我设置$youtube video=“”;它可以工作,但如果我设置$youtube video=get_post_meta($post->ID,'youtube video',true);它不起作用!