Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ilicfilip/ce62e0dcc750ada3aa4817556af7d079 to your computer and use it in GitHub Desktop.
Save ilicfilip/ce62e0dcc750ada3aa4817556af7d079 to your computer and use it in GitHub Desktop.
function avada_set_post_views() {
global $post;
if ( 'post' === get_post_type() && is_single() ) {
$post_id = $post->ID;
if ( ! empty( $post_id ) ) {
$count_key = 'avada_post_views_count';
$count = get_post_meta( $post_id, $count_key, true );
if ( empty( $count ) ) {
$count = 0;
// delete_post_meta( $post_id, $count_key );
add_post_meta( $post_id, $count_key, '0' );
} else {
$count++;
update_post_meta( $post_id, $count_key, $count );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment