Title: exclude attachments from
Last modified: April 14, 2024

---

# exclude attachments from

 *  Resolved [ehsanmn](https://wordpress.org/support/users/ehsanmn/)
 * (@ehsanmn)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/exclude-attachments-from/)
 * I show most viewed attachments in my site footer with this code :
 *     ```wp-block-code
                           <?php
                               $amir_query = array (
                                   'range' => 'custom',
                                   'time_quantity' => 1,
                                   'time_unit' => 'hour',
                                   'order_by' => 'views',
                                   'post_type' => 'attachment',
                                   'limit' => 3,
                                   'thumbnail_width' => 75,
                                   'thumbnail_height' => 75,
                                   'stats_views' => 1,
                                   'cat' => '-202',
                                   'post_html' => '
                                       <div class="post"><figure class="post-thumb"><a href="{url}">{custom_thumb}</a></figure><div class="post_title"><h5><a href="{url}">{title}</a></h5></div></div>
                                   ',
                                   );
                                   if (function_exists('wpp_get_mostpopular'))
                                   wpp_get_mostpopular($amir_query);
                           ?>
       ```
   
 * I want to exclude some attachments from this list by ids, any idea?
 * my site link : [https://mwallpaper.ir/?p=6544](https://mwallpaper.ir/?p=6544)(
   footer)

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

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/exclude-attachments-from/#post-17685731)
 * Hi [@ehsanmn](https://wordpress.org/support/users/ehsanmn/),
 * Use the **pid** parameter to exclude IDs from the list, see [Parameters](https://github.com/cabrerahector/wordpress-popular-posts/wiki/2.-Template-tags#parameters)
   for more details.
 *  Thread Starter [ehsanmn](https://wordpress.org/support/users/ehsanmn/)
 * (@ehsanmn)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/exclude-attachments-from/#post-17685873)
 * I tested that with Both the parent post ID and attachment ID, but its not working.
 * I think because **pid** is for post_type=posts and does not work for attachments.
 * for showing attachments with **wpp_get_mostpopular** I added a snippet code to
   functions.php to show items that have inherit post_status (like attachments)
 * `function wp8762_include_inherit_status( $where, $options ) {
   return $where ."
   OR p.post_status = 'inherit'";}add_filter( 'wpp_query_where', 'wp8762_include_inherit_status',
   10, 2 );
 * I think need a snippet code like this to add **pid** parameter for attachment
   IDs too.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/exclude-attachments-from/#post-17685978)
 * > I think because **pid** is for post_type=posts and does not work for attachments.
 * That’s not correct. The pid parameter works for all post types.
 * Please share your updated code here so I can see if there’s something that needs
   adjustments.
 *  Thread Starter [ehsanmn](https://wordpress.org/support/users/ehsanmn/)
 * (@ehsanmn)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/exclude-attachments-from/#post-17697404)
 * this is my code :
 *     ```wp-block-code
                           <?php
                               $amir_query = array (
                                   'range' => 'custom',
                                   'time_quantity' => 1,
                                   'time_unit' => 'hour',
                                   'order_by' => 'views',
                                   'post_type' => 'attachment',
                                   'limit' => 3,
                                   'pid' => '4346',
                                   'thumbnail_width' => 75,
                                   'thumbnail_height' => 75,
                                   'stats_views' => 1,
                                   'post_html' => '
                                       <div class="post"><figure class="post-thumb"><a href="{url}">{custom_thumb}</a></figure><div class="post_title"><h5><a href="{url}">{title}</a></h5></div></div>
                                   ',
                                   );
                                   if (function_exists('wpp_get_mostpopular'))
                                   wpp_get_mostpopular($amir_query);
                           ?>
       ```
   
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [2 years, 1 month ago](https://wordpress.org/support/topic/exclude-attachments-from/#post-17703020)
 * Alright, finally had time to look into this.
 * Did some testing and found out that the problem is [this wpp_query_where filter hook](https://wordpress.org/support/topic/exclude-attachments-from/#post-17685873).
   Please change it to this and the pid parameter should work as intended:
 *     ```wp-block-code
       function wp8762_include_inherit_status( $where, $options ) {
       	$where = str_replace("p.post_status = 'publish'", "(p.post_status = 'publish' OR p.post_status = 'inherit')", $where);
       	return $where;
       }
       add_filter( 'wpp_query_where', 'wp8762_include_inherit_status', 10, 2 );
       ```
   

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

The topic ‘exclude attachments from’ 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/)

## Tags

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

 * 5 replies
 * 2 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [2 years, 1 month ago](https://wordpress.org/support/topic/exclude-attachments-from/#post-17703020)
 * Status: resolved