Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress自定义设置返回10NULL_Php_Wordpress - Fatal编程技术网

Php Wordpress自定义设置返回10NULL

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

我在wp_选项中添加了自定义字段

字段名为折扣,值为10(varchar)

结果为10NULL

我需要转换为整数

请尝试在1以下

$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 );