• Resolved Jack Johansson

    (@mhmdshv)


    Hi.

    I’ve been using this plugin for a while, works fine. However i would like to get the views for a post outside of the loop, without the shortcode. The the_views() function lacks an option to manually feed it with the post id.

    Would be really nice to add a simple argument for the ID.

    Currently i’m using $post->ID=$myID; to fix the issue.

    5/5 as always.

Viewing 1 replies (of 1 total)
  • Plugin Author Lester Chan

    (@gamerz)

    Not sure why you can’t just do <?php echo intval( get_post_meta( $id, 'views', true ) ); ?>

    Or you can make it to your own function

    
    function the_views_with_id( $id ) {
    	$views_options = get_option( 'views_options' );
    	$post_views = intval( get_post_meta( $id, 'views', true ) );
    	echo str_replace( array( '%VIEW_COUNT%', '%VIEW_COUNT_ROUNDED%' ), array( number_format_i18n( $post_views ), postviews_round_number( $post_views) ), stripslashes( $views_options['template'] ) );
    }
    

    Or you can use the shortcode workaround

    <?php echo do_shortcode('[views id="' . $id . '"]'); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Get views by post id out of the loop?’ is closed to new replies.