2013-05-11 95 views
0

我试图在我的网站上显示自定义字段,但无法返回前端中的任何值。显示自定义字段值

首先,我添加了这个功能添加到functions.php:

function get_custom_field($custom_field) { 
    global $post; 
    $custom_field = get_post_meta($post ->ID, custom_field, true) ; 
    return $custom_field , 
} 

在我page.php文件添加此:

<?php if (function_exists('get_custom_field')) { 
    get_custom_field('distance', true) ; 
} ?> 

“距离”字段是我创建的自定义字段想要显示。

任何方向都会很棒。

回答

1

您是否错过了custom_field中的$符号? 修复:

$custom_field = get_post_meta($post->ID, $custom_field, true); 
在你需要使用只有一个参数调用函数

。我可以看到,在函数中只有一个参数,代码:

<?php if (function_exists('get_custom_field')) { 
    get_custom_field('distance') ; } ?> 
+0

并且在返回指令中使用'''而不是';'。 – 2013-05-11 11:49:49

相关问题