我做了这些树教程来创建自定义metaboxes。
http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-1-intro-and-basic-fields/ http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-2-advanced-fields/ http://wp.tutsplus.com/tutorials/reusable-custom-meta-boxes-part-3-extra-fields/
但我不知道如何从单个字段调用值。我使用了这个php脚本$meta = get_post_meta($post->ID,$field‘’custom_text‘,true);回显$meta;
但是id不起作用。有人知道我做错了什么吗。
发布于 2012-03-02 19:39:46
好吧,如果不看一下你是如何实现你的自定义元函数的,那就很难说了--那里可能有个问题--但同时,检查一下WordPress文档,以确保你正确地使用了get_post_meta()函数。第二个参数应该是一个字符串,它表示要检索的元字段的键(名称)。
摘自Codex:
$meta_values = get_post_meta($post_id, $key, $single);
// where $key = A string containing the name of the meta value you want.因此,请仔细检查您正在传递的值($ field‘contain’)是否确实包含一个字符串,该字符串表示您试图检索的元字段的名称。
发布于 2012-03-03 02:13:32
正如之前的帖子所说,您使用get_post_meta是错误的。假设您在自定义元框中创建了一个名为"custom_field“的自定义字段,您将使用以下代码获取所述字段的值:
$field_value = get_post_meta($post_id, 'custom_field', true);
echo $field_value; // outputs the field value.如果这不起作用,你要么是把字段的名字弄错了,要么是你在添加metabox时做错了什么,如果是这样的话,检查你的php错误日志中的错误。
https://stackoverflow.com/questions/9530656
复制相似问题