Wordpress页面ID自定义字段
问题描述:
所以我有以下代码。Wordpress页面ID自定义字段
function field_func($atts) {
global $post;
$name = $atts['name'];
if (empty($name)) return;
return get_post_meta($post->ID, $name, true);
}
add_shortcode('field', 'field_func');
这让我使用短码,[field name='fieldname']
显示当前页面的自定义字段中的值。但是,如何使用ID在此页面上显示其他帖子/页面的自定义字段?需要添加什么代码才能通过第二个参数id='pageid'
?
答
function field_func($atts) {
global $post;
$name = $atts['name'];
$id = $atts['id'];
...do whatever with $id and $name...
}
add_shortcode('field', 'field_func');
,并呼吁与
[field name='fieldname' id='pageid']
@Veloncia林不知道你对这个问题的最终应用是什么,但如果你做了很多,在WordPress的自定义字段的工作我会建议寻找到高级自定义字段,它是一个非常棒的免费插件。 API,文档和支持都是一流的,并使定制领域变得轻而易举 http://www.advancedcustomfields.com/ – celeriko