Title: Using with get_posts()
Last modified: August 21, 2016

---

# Using with get_posts()

 *  [crdunst](https://wordpress.org/support/users/crdunst/)
 * (@crdunst)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/using-with-get_posts/)
 * 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/](https://wordpress.org/plugins/baw-post-views-count/)

The topic ‘Using with get_posts()’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/baw-post-views-count_ffffff.svg)
 * [Post Views Count (Support caching plugins!)](https://wordpress.org/plugins/baw-post-views-count/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/baw-post-views-count/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/baw-post-views-count/)
 * [Active Topics](https://wordpress.org/support/plugin/baw-post-views-count/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/baw-post-views-count/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/baw-post-views-count/reviews/)

## Tags

 * [manual](https://wordpress.org/support/topic-tag/manual/)

 * 0 replies
 * 1 participant
 * Last reply from: [crdunst](https://wordpress.org/support/users/crdunst/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/using-with-get_posts/)
 * Status: not resolved