Title: ffd8's Replies | WordPress.org

---

# ffd8

  [  ](https://wordpress.org/support/users/ffd8/)

 *   [Profile](https://wordpress.org/support/users/ffd8/)
 *   [Topics Started](https://wordpress.org/support/users/ffd8/topics/)
 *   [Replies Created](https://wordpress.org/support/users/ffd8/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/ffd8/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/ffd8/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/ffd8/engagements/)
 *   [Favorites](https://wordpress.org/support/users/ffd8/favorites/)

 Search replies:

## Forum Replies Created

Viewing 1 replies (of 1 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Scraping images, excluding categories](https://wordpress.org/support/topic/scraping-images-excluding-categories/)
 *  Thread Starter [ffd8](https://wordpress.org/support/users/ffd8/)
 * (@ffd8)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/scraping-images-excluding-categories/#post-6166941)
 * Solved the problem [ignore wrong ‘remove_filter’ above]! It seems to be true 
   that when doing attachments/images query, it ignores all filtering of categories
   I threw at it… Instead, one can ask for the image object’s post_parent, then 
   do an in_category() test to exclude the ones to be ignored:
 *     ```
       $ads = array(2,4); // list of cats to exclude
       $media_query = new WP_Query(array(
         	'post_type' => 'attachment',
       	'post_mime_type' =>'image',
       	'post_status' => 'inherit',
       	'posts_per_page' => -1,
       ));
   
       foreach ($media_query->posts as $post) {
       	if (!in_category($ads, $post->post_parent)){
       		$img = wp_get_attachment_image_src($post->ID, $imgSize)[0];
       		echo '<img src="'.$img.'" id="">';
       	}
       }
       ```
   
 * Hope that helps someone trying to scrape their images too…

Viewing 1 replies (of 1 total)