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 0
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: errorsPHP WarningA nonnumeric value encountered