1

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

0

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.