Я следовал руководству и каждый раз успешно мог подсчитать человек нажимает на сообщение, используя этот код:
Код: Выделить всё
function increment_post_views() {
if (is_single()) {
$post_id = get_the_ID();
$views = get_post_meta($post_id, 'products_views', true);
// If the 'post_views' meta field doesn't exist, initialize it to 1
if (empty($views)) {
$views = 1;
} else {
$views = intval($views) + 1;
}
// Update the 'post_views' meta field with the incremented value
update_post_meta($post_id, 'products_views', $views);
}
}
add_action('wp', 'increment_post_views');
Подробнее здесь: https://stackoverflow.com/questions/790 ... ent-the-co