WordPress.org

Ready to get started?Download WordPress

Forums

Post Views Count
Using with get_posts() (1 post)

  1. crdunst
    Member
    Posted 5 months ago #

    Hi,

    Your plugin seems to work great for normal pages/posts.

    I am using a custom post type for advertisements - they are non public posts, but I retrieve them using get_posts() to display around my site.

    Viewing the post in this way doesn't increment the view count, so I was looking for a way to manually increment the view count based on the post id. I can see you have some filters available that may do this, but I can't figure it out.

    My code is as follows:

    $args = array(
    	'post_type' => 'advert',
    	'posts_per_page' => 2,
    	'orderby' => 'rand',
    	'post_status' => 'publish'
    );
    $posts = get_posts( $args );
    
    foreach ($posts as $post) :  setup_postdata($post);
    
    	// I'm displaying my advert here
    
    	// how do I manually increase the view count here?
    
    endforeach;
    wp_reset_query();

    Do you have a quick pointer how I can write back to increment the counter?

    Thanks in advance

    https://wordpress.org/plugins/baw-post-views-count/

Reply

You must log in to post.

About this Plugin

About this Topic