📜  wp post view - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:32.926000             🧑  作者: Mango

代码示例1
function bac_PostViews($post_ID) {

    $count_key = 'post_views_count';
    $count = get_post_meta($post_ID, $count_key, true);

    if($count == ''){
        $count = 0;
        delete_post_meta($post_ID, $count_key);
        add_post_meta($post_ID, $count_key, '0');
        return $count . ' Visitas';

    }else{
        $count++; 
        update_post_meta($post_ID, $count_key, $count);

        if($count == '1'){
        return $count . ' Visita';
        }
        else {
        return $count . ' Visitas';
        }
    }
}