这段代码每次都会增加 5+ 次 [Total Post View Wordpress]

问题描述

每次 [Total Post View wordpress] 任何人都必须解决此问题时,此代码增加 5 倍以上,请帮忙。我正在使用简码方法在单个帖子中打印总视图

function bac_PostViews($post_ID) {
 
    //Set the name of the Posts Custom Field.
    $count_key = 'post_views_count'; 
     
    //Returns values of the custom field with the specified key from the specified post.
    $count = get_post_meta($post_ID,$count_key,true);
     
    //If the the Post Custom Field value is empty. 
    if($count == ''){
        $count = 0; // set the counter to zero.
         
        //Delete all custom fields with the specified key from the specified post. 
        delete_post_Meta($post_ID,$count_key);
         
        //Add a custom (Meta) field (Name/value)to the specified post.
        add_post_Meta($post_ID,'0');
        return $count . ' View';
     
    //If the the Post Custom Field value is NOT empty.
    }else{
        $count++; //increment the counter by 1.
        //Update the value of an existing Meta key (custom field) for the specified post.
        update_post_Meta($post_ID,$count);
         
        //If statement,is just to have the singular form 'View' for the value '1'
        if($count == '1'){
        return $count . ' View';
        }
        //In all other cases return (count) Views
        else {
        return $count . ' Views';
        }
    }
}
// post total view
function post_total_view() {

    if(function_exists('bac_PostViews')) { 
        echo bac_PostViews(get_the_ID()); 
    }

}
add_shortcode( 'total_post_view','post_total_view' );

检查这张图片-- enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)