• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

[HELP] Warning: A non-numeric value encountered

Status
Not open for further replies.

Testosterone

Member
Jun 1, 2019
93
52
18
Hi guys,

I got a problem with a theme:

Warning: A non-numeric value encountered in ...\functions\popcorn_post_like.php on line 60 ($total_count = $like_count + $dislike_count;)
Code:
<?php
function load_postlike_script(){  
    wp_register_script('like_post', get_template_directory_uri().'/awpt/js/post-like/post-like.min.js', array('jquery'), '1.1', true );
    wp_enqueue_script('like_post');
    wp_localize_script('like_post', 'ajax_var', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('ajax-nonce')
));
add_action('wp_ajax_nopriv_post-like', 'adultwpthemes_post_like');
add_action('wp_ajax_post-like', 'adultwpthemes_post_like');
}
add_action('init', 'load_postlike_script');
$timebeforerevote = 1;//1 * 60min * 24h
function adultwpthemes_hasAlreadyVoted($post_id)
{
    global $timebeforerevote;

    $meta_IP = get_post_meta($post_id, "voted_IP");
    $voted_IP = isset($meta_IP[0]) ? $meta_IP[0] : '';
    if(!is_array($voted_IP))
        $voted_IP = array();
    $ip = $_SERVER['REMOTE_ADDR'];
   
    if(in_array($ip, array_keys($voted_IP)))
    {
        $time = $voted_IP[$ip];
        $now = time();
       
        if(round(($now - $time) / 60) > $timebeforerevote)
            return false;
           
        return true;
    }
   
    return false;
}
function adultwpthemes_getPostLikeLink($post_id) {
    global $awpt,$post;
    /*$rates = (int) get_post_meta( $post->ID, 'likes_count', true) + (int) get_post_meta( $post->ID, 'dislikes_count', true);
   $votes = adultwpthemes_getItemPostLikeRate( $post_id );*/
   $output = '<span class="vote-system">';
        $output .= '<div class="vote_buttons"><a href="#" data-post_id="'.$post_id.'" data-post_like="like" class="l-vote positivelike">
        <img src="' . get_bloginfo("template_url") . '/awpt/css/images/positivelike.png" alt="' . __('I like this video', 'adultwpthemes') . '">
        <i class="tool-tip"><em></em>' . __('Good', 'adultwpthemes') . '</i>
        </a>
      <a href="#" data-post_id="'.$post_id.'" data-post_like="dislike" class="l-vote negativelike">
      <img src="' . get_bloginfo("template_url") . '/awpt/css/images/negativelike.png" alt="' . __('I dont like this video', 'adultwpthemes') . '">
        <i class="tool-tip"><em></em>' . __('Bad', 'adultwpthemes') . '</i>
        </a>
      <div class="vote">
      <span>' . get_template_part( 'templates/vote', get_post_format() ) . '</span></div>
        </div>
      ';
      $output .= '</span>';
return $output;
}
function adultwpthemes_getPostLikeRate( $post_id ){
    $like_count     = get_post_meta($post_id, "likes_count", true);
    $dislike_count  = get_post_meta($post_id, "dislikes_count", true);
    $total_count    = $like_count + $dislike_count;
    if($total_count > 0)
        return $like_count / $total_count * 100;
    else
        return false;
}
function adultwpthemes_getItemPostLikeRate( $post_id ){
   
    if( adultwpthemes_getPostLikeRate($post_id) !== false )
        return floor( adultwpthemes_getPostLikeRate($post_id) ) . '%';
    else
        return '0%';
   
}

I don't know why it treats these values as non-numeric.

Can the js file (post-like.min.js) contains errors?




---------------------------
just added (int) before variables and it worked. Silly me.

@Babak please close the tread.
 
Last edited:
Status
Not open for further replies.
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock