我正在使用Wordpress与Genesis Framework,如果他们需要显示自定义字段的值,我就很难显示#34; 0"。值来自一个表单,0值确实在我的数据库的post meta中。如果我将它们更改为其他任何内容,它们将完美地显示在single-posttype.php模板上。但是,如果将它们设置为0,则不显示任何内容。我已经提供了一个我正在使用的代码示例,是的,我知道我的脏代码,但是没关系。我知道我的位置。帮助
$customField = genesis_get_custom_field('customField');
add_action('hookLocation','myDirtyShortcodes');
function myDirtyShortcodes(){
echo do_shortcode('[some dirtyshortcodehere'.$customField.' more dirty shortcode]');
}
答案 0 :(得分:0)
正如@Machevity所提到的那样尝试:
add_action('hookLocation','myDirtyShortcodes');
function myDirtyShortcodes(){
$customField = genesis_get_custom_field('customField');
echo do_shortcode('[some dirtyshortcodehere'.$customField.' more dirty shortcode]');
}
答案 1 :(得分:0)
固定。 genesis_get_custom_field函数使用了一种检查变量为空值的糟糕方法。
genesis_get_custom_field里面,
if ( ! $custom_field )
return '';
替换为
if($custom_field === '')
return '';
在原始功能中," 0"是假的。但是这个快速的改变(感谢Reddit上的/ u / gu3st12)。