I get this Warning: A non-numeric value encountered in /home/customer/www/example.com/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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Post 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0