Code for most popular post

<?php 
		$key = 'views';
		$meta = get_post_meta( $post_id,$key );
		if(!empty($meta))
		{
			$newVal=$meta[0]+1;
			update_post_meta($post_id,$key, $newVal);
		}
		else
		{
			$newVal = 1;
			add_post_meta( $post_id,$key, $newVal );
		}
		?>

Leave a Reply