Warning: A non-numeric value encountered in line 107.
<div class="like">
<?php
$nonce = wp_create_nonce("my_user_vote_nonce");
$likeLink = admin_url('admin-ajax.php?action=my_user_vote&custom=like&post_id='.$post->ID.'&nonce='.$nonce);
?>
<a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>
</div>
line 107
<a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>
Warning: A non-numeric value encountered in line 107.
<div class="like">
<?php
$nonce = wp_create_nonce("my_user_vote_nonce");
$likeLink = admin_url('admin-ajax.php?action=my_user_vote&custom=like&post_id='.$post->ID.'&nonce='.$nonce);
?>
<a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>
</div>
line 107
<a class="like" data-image="<?php bloginfo('template_url');?>/images/loading.gif" data-field="like" data-nonce="<?php echo $nonce ?>" data-post_id="<?php echo $post->ID ?>" href="<?php echo $link ?>" title="Like"><span><?php echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.'); ?></span></a>
Share
Improve this question
edited Mar 13, 2020 at 12:12
Ersin
asked Mar 13, 2020 at 11:45
ErsinErsin
31 silver badge3 bronze badges
2
- You have a lot of stuff on that line, can you split it into multiple lines so that we can figure out which part is the problem? I have a suspicion where it is. Otherwise, are you asking where the warning is, what the warning means, or are you asking how to fix it? – Tom J Nowell ♦ Commented Mar 13, 2020 at 12:06
- Thank you Tom for your help, i want to fix it. Why it is happening with PHP 7.1. – Ersin Commented Mar 13, 2020 at 12:13
1 Answer
Reset to default 1I suspect the problem is this:
echo number_format(get_post_meta($post->ID, "like", true) * 1, 0, ',', '.')
Here, we take the post meta named like
and multiply it by 1, but what if that post meta doesn't contain a number? What if it contains something else?
For example, if we did 2 x 4
, we would expect PHP to give us 8, which is correct, but what if we tell PHP to multiple 2 x "hello"
? or