Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save larbous/ae2d9490998e40baf9da2923b9f2c84c to your computer and use it in GitHub Desktop.
Save larbous/ae2d9490998e40baf9da2923b9f2c84c to your computer and use it in GitHub Desktop.
Contador de Views para WordPress Posts e CPT
/*Desenvolvido por Dante Testa + ASK Jarvis*/
/*Coloque esse código no functions.php do seu tema */
/*https://www.youtube.com/watch?v=NKxyNbJbee4 */
function views_shortcode( $atts ) {
$a = shortcode_atts( array(
'print' => '0',
'count' => '0',
), $atts );
$print = $a['print'];
$count = $a['count'];
if($count == 1){
$views = get_post_meta(get_the_ID(), 'views', true);
$views++;
update_post_meta(get_the_ID(), 'views', $views);
}
if($print == 1){
$views = get_post_meta(get_the_ID(), 'views', true);
return $views;
}
}
add_shortcode( 'views', 'views_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment