在wordpress的前端访问并具有有效的元框字段


Access and have functioning meta box fields on front end of wordpress

我目前正在wordpress的前端使用我在这里找到的代码发帖http://voodoopress.com/review-of-posting-from-front-end-form/

然而,我使用了一些插件,它们在后端的元框中有更高的字段,我似乎无法将数据从前端表单传递到这些字段。其中一个插件是wordpress facebook插件http://wordpress.org/extend/plugins/facebook/想要访问的字段id是建议好友id,因为它可以在您键入时为当前好友自动完成ajax facebook。这是前端的一种可能性,还是我在尝试不可能的事情?

感谢

如果我理解你的问题,这就是你需要的函数:http://codex.wordpress.org/Function_Reference/get_post_meta

他们在文档中给出的使用示例是:

<?php $meta_values = get_post_meta($post_id, $key, $single); ?> 

对于第一个值$post_id,可以按照以下说明操作:

$post_id是您想要元值的帖子的id。使用$post->ID以获取$post变量范围内的帖子ID。使用get_the_ID()检索WordPress中当前项目的ID环路

所以,如果你在你的模板页面$post->ID会很好。

接下来,你需要$key才能成为"推荐朋友"

最后,$single-set-true返回字符串

所以你可以用这个作为你的最终结果:

<?php 
$suggestFriends = get_post_meta($post->ID, 'suggest-friends', true);
echo 'The value of suggest-friends for this post is: '.$suggestFriends;
?>

希望能有所帮助!