自定义字段的值,我用这个代码functions.php文件:获得从具体职位
function get_custom_field_value($szKey, $bPrint = false) {
global $post;
$szValue = get_post_meta($post->ID, $szKey, true);
if ($bPrint == false) return $szValue; else echo $szValue;}
,这一次在我的HTML引用它,当我需要得到一个自定义字段:
<?php if (function_exists('get_custom_field_value')){
get_custom_field_value('now_location', true);} ?>
但是,只有当我在帖子中使用它时才起作用,因为它需要当前帖子的字段值。
如何从一个确切的帖子中获得字段值(或多个)? 我想它与帖子的ID有关,但我不知道要更改/添加到代码中。
你在用什么?什么是$ post,cus它与$ _POST – Niels
不一样$ $ post是如何工作的? –
我刚刚从[这里]复制了代码(http://www.wprecipes.com/how-to-easily-get-the-value-of-a-custom-field)。 正如我所说的,当我在帖子中使用它时它工作正常,但当我想要从特定帖子获取特定字段值并在单独的'div'中显示值时,它不会正常工作。 – rlesko