Php Wordpress自定义设置返回10NULL
我在wp_选项中添加了自定义字段 字段名为折扣,值为10(varchar) 结果为10NULL 我需要转换为整数请尝试在1以下Php Wordpress自定义设置返回10NULL,php,wordpress,Php,Wordpress,我在wp_选项中添加了自定义字段 字段名为折扣,值为10(varchar) 结果为10NULL 我需要转换为整数请尝试在1以下 $discount = (int) get_option('discount'); return var_dump($discount); 在您的上下文中,该选项是错误的,它们提供了有关当前站点的信息。如果需要选项表wp\u options中的值,则应使用 在您的环境中,以下内容应该有效: $discount = (int) get_option( 'discount
$discount = (int) get_option('discount');
return var_dump($discount);
在您的上下文中,该选项是错误的,它们提供了有关当前站点的信息。如果需要选项表wp\u options
中的值,则应使用
在您的环境中,以下内容应该有效:
$discount = (int) get_option( 'discount' );
var_dump( $discount );
如果该字段的值真的是整数(10),则应添加
(int)
以获得实数类型的整数。(int)无法帮助我为什么?为什么要使用var_dump呢?我尝试了(int)和$discount=bloginfo('discount')*1;但结果是一样的,结果是10int(0),所以它是有效的,它是正确的吗?因此,始终使用get_选项从选项表中获取值
$discount = (int) get_option( 'discount' );
var_dump( $discount );