Title: Exclude Posts
Last modified: March 2, 2021

---

# Exclude Posts

 *  Resolved [Rami](https://wordpress.org/support/users/rami4625/)
 * (@rami4625)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/exclude-posts-11/)
 * Hello,
    I want to ask how I can exclude post from showing in the best week views
   if it showing in the best month views?
 * I use the code for week views :
    <?php if ( function_exists(‘wpp_get_mostpopular’)){
   wpp_get_mostpopular(array( ‘limit’ => 5, ‘range’ => ‘last7days’, ‘order_by’ =
   > ‘views’, ‘stats_views’ => 0 )); } ?>
 * And this code for month views :
    <?php if ( function_exists(‘wpp_get_mostpopular’)){
   wpp_get_mostpopular(array( ‘limit’ => 5, ‘range’ => ‘last30days’, ‘order_by’ 
   => ‘views’, ‘stats_views’ => 0 )); } ?>
    -  This topic was modified 5 years, 3 months ago by [Rami](https://wordpress.org/support/users/rami4625/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/exclude-posts-11/#post-14124901)
 * Hi [@rami4625](https://wordpress.org/support/users/rami4625/),
 * That’s not really possible without some custom coding work: you’d need to retrieve
   the IDs of the most popular posts from the last 7 days (you can use the [\WordPressPopularPosts\Query](https://github.com/cabrerahector/wordpress-popular-posts/blob/5.2.4/src/Query.php)
   class for this for example) and then pass these IDs to the second function using
   the `pid` parameter.
 *  Thread Starter [Rami](https://wordpress.org/support/users/rami4625/)
 * (@rami4625)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/exclude-posts-11/#post-14142221)
 * Hi [@hcabrera](https://wordpress.org/support/users/hcabrera/) ,
 * Thanks for respond,
    Can you give me specific example to do that? That’s will
   help me more.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/exclude-posts-11/#post-14142752)
 * Sure thing, [@rami4625](https://wordpress.org/support/users/rami4625/). Here 
   you go: [Get popular posts IDs as an array, no HTML](https://wordpress.org/support/topic/get-popular-post-id-as-an-array-with-no-html/).
 *  Thread Starter [Rami](https://wordpress.org/support/users/rami4625/)
 * (@rami4625)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/exclude-posts-11/#post-14171580)
 * That’s work but I should use (implode) to make it work,
 * The code now look like this:
 * <?php
    if ( function_exists(‘wpp_get_mostpopular’) ) {
 *  // Get Popular Posts IDs
    function get_popular_posts_ids($range, $limit) { $
   post_IDs = array(); $query = new \WordPressPopularPosts\Query([ ‘range’ => $range,‘
   limit’ => $limit ]); $popular_posts = $query->get_posts(); // Popular posts found,
   get their IDs if ( is_array($popular_posts) && ! empty($popular_posts) ) { foreach(
   $popular_posts as $popular_post) { $post_IDs[] = $popular_post->id; } } return
   $post_IDs; }
 *  // Gets the 5 most viewed posts from the last 30 days
    $post_ids_array = get_popular_posts_ids(‘
   last30days’, 5);
 *  // Gets Each Item In $post_ids_array
    $post_ids_items = implode(“,”, $post_ids_array);
 *  wpp_get_mostpopular(array(
    ‘limit’ => 5, ‘range’ => ‘last7days’, ‘order_by’
   => ‘views’, ‘stats_views’ => 0, ‘pid’ => $post_ids_items ));
 *  }
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Exclude Posts’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Rami](https://wordpress.org/support/users/rami4625/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/exclude-posts-11/#post-14171580)
 * Status: resolved