Created
May 21, 2020 15:35
-
-
Save ilicfilip/ce62e0dcc750ada3aa4817556af7d079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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