如何在页面
-
-
它确实是`get_post_meta()`函数,如果您在循环内调用它,它应该可以工作...除非您没有使用正确的自定义字段名称.如果通过诸如meta-box之类的插件实现,则它们通常带有前缀.您可以张贴代码如何声明自定义字段吗?一种解决方案是在PhpMyAdmin中打开wp_postmeta表,并在"meta_key"列中搜索LIKE%...%,并将" subtitle"指定为meta_key值.您将确切看到Wordpress用来存储自定义字段的名称.it is indeed the `get_post_meta()` function, and if you are calling it inside the loop, it should work... Unless you're not using the right custom field name. They often come with a prefix if they are implemented via a plugin like meta-box. Can you post the code how you declare your custom fields? A solution would be to open the wp_postmeta table in PhpMyAdmin and search the column `meta_key` for LIKE %...% and specify "subtitle" as meta_key value. You will see exactly under what name Wordpress is storing your custom field.
- 0
- 2013-09-13
- pixeline
-
我知道这很旧,但我使用此sql获取phpmyadmin中所有元字段的列表:从wp_postmetam选择BYm.meta_keyI know this is old, but I use this sql to get a list of all meta fields in phpmyadmin: SELECT m.meta_key FROM wp_postmeta m GROUP BY m.meta_key
- 0
- 2015-11-10
- ssaltman
-
2 个回答
- 投票数
-
- 2013-09-13
好,您正在使用:
get_post_meta(get_the_ID(), 'subtitle', TRUE);
因此,您对Wordpress说要获取"字幕"字段的元值,并且返回的值应为字符串格式.参见get_post_meta()文档.
要获取帖子的所有元数据,您应该改用get_post_custom()函数.例如,如果您在循环中:
$custom = get_post_custom(); foreach($custom as $key => $value) { echo $key.': '.$value.'<br />'; }
这将返回帖子的所有元数据.例如,如果您要检查"价格"元字段:
if(isset($custom['price'])) { echo 'Price: '.$custom['price'][0]; }
Well, you are using:
get_post_meta(get_the_ID(), 'subtitle', TRUE);
So, you are saying to Wordpress to get the meta value of the 'subtitle' field and that the returned value be in format of string. See get_post_meta() docu.
To get all meta data of a post you should use get_post_custom() function instead. For example, if you are inside the loop:
$custom = get_post_custom(); foreach($custom as $key => $value) { echo $key.': '.$value.'<br />'; }
This will return all meta data of the post. If you want to check, for example, the "price" meta field:
if(isset($custom['price'])) { echo 'Price: '.$custom['price'][0]; }
-
- 2015-07-30
使用此代码解决您的问题.
$key_name = get_post_custom_values($key = 'Key Name'); echo $key_name[0];
use this code for solving your problem.
$key_name = get_post_custom_values($key = 'Key Name'); echo $key_name[0];
我有一个称为"软件"的自定义帖子类型,其中包含各种自定义字段,例如字幕,价格,屏幕截图,下载链接等.我创建了一个函数,以允许对其中一些自定义使用tinyMCE编辑窗口领域.我一直试图在页面上显示这些字段,但没有成功.
我正在使用的方法是这样:
此处是该页面的链接./p>
页面上
<hr/>
下方是所有已创建元的列表.出于某些奇怪的原因,将仅显示"价格"字段.有人知道我想念什么吗?