Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter ffd8

    (@ffd8)

    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)