admin管理员组文章数量:1323728
I get this Warning: A non-numeric value encountered in /home/customer/www/example/public_html/wp-content/themes/boombox/includes/functions.php on line 2466
I try to change it from => $manual_amount + $user_votes; to $manual_amount += $user_votes; (it throws same warning) and $manual_amount . $user_votes; (it concatenates the numbers, does not add them)
/**
* Return post point count
*
* @param $post_id
*
* @return int
*/
function boombox_get_post_point_count($post_id)
{
$points_count = 0;
/*if ( boombox_module_management_service()->is_module_active( 'prs' ) ) {
$points_count = Boombox_Point_Count_Helper::get_post_points( $post_id );
}*/
$manual_amount = get_post_meta($post_id, "manual_vote_amount", true);
$user_votes = get_post_meta($post_id, "add_vote_amount", true);
$points_count = $manual_amount + $user_votes;
return $points_count;
}
I'd appreciate your help
I get this Warning: A non-numeric value encountered in /home/customer/www/example/public_html/wp-content/themes/boombox/includes/functions.php on line 2466
I try to change it from => $manual_amount + $user_votes; to $manual_amount += $user_votes; (it throws same warning) and $manual_amount . $user_votes; (it concatenates the numbers, does not add them)
/**
* Return post point count
*
* @param $post_id
*
* @return int
*/
function boombox_get_post_point_count($post_id)
{
$points_count = 0;
/*if ( boombox_module_management_service()->is_module_active( 'prs' ) ) {
$points_count = Boombox_Point_Count_Helper::get_post_points( $post_id );
}*/
$manual_amount = get_post_meta($post_id, "manual_vote_amount", true);
$user_votes = get_post_meta($post_id, "add_vote_amount", true);
$points_count = $manual_amount + $user_votes;
return $points_count;
}
I'd appreciate your help
Share Improve this question asked Sep 15, 2020 at 3:41 Luis LlanosLuis Llanos 131 silver badge3 bronze badges 01 Answer
Reset to default 1Post meta values are stored as strings in the database, so you get only strings back. If you want to use these value in mathematical operations, you have to cast the value to a numeric type, meaning you write the desired type in parentheses in front of the variable or the function call.
Generic example:
$number = (int) get_post_meta($post_id, "key_identifier", true);
And then you can use the variable with a +
sign.
本文标签: errorsPHP WarningA nonnumeric value encountered
版权声明:本文标题:errors - PHP Warning : A non-numeric value encountered 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742120085a2421653.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论