Tag Info

Hot answers tagged


Pretty much the solution is to include all mimes except images. WordPress has a nifty little function where it keeps all it's accepted mime-types called get_allowed_mime_types() ( cleverly named ) which returns an Array() of mimes. All we need to do is get the difference between the returned array and the array of mime-types we don't want in our query: ...


If you also want to include post types other than attachments (e.g. posts, pages) that don't have any mime type, you'll have to use the posts_where filter: add_filter( 'posts_where' , 'remove_images' ); function remove_images($where) { global $wpdb; $where.=' AND '.$wpdb->posts.'.post_mime_type NOT LIKE \'image/%\''; return $where; }


I'm pretty much certain there isn't an equivalent of posts_not_in for mime types. You could of course query for all attachments that are images. Preferably just returning the IDs via parameter fields set to ids. Then you can use those IDs with posts__not_in on a second query. Drawback being that you need two queries. Another possibility would be to hook ...


All those complex functions can be reduced to one simple function: attachment_url_to_postid() You only need to parse the image URL to retrieve the attachment ID: $attachment_id = attachment_url_to_postid( $image_url ); echo $attachment_id; That's all you need.


wp_get_attachment_thumb_url() doesn't accept three parameters. It takes one-- the attachment ID. And, as you might guess from the name of the function, it return the thumbnail URL *_thumb_url. If you'd have simply checked the Codex entry for the function you'd have seen that. If you'd check the Codex, you'd see several other things too Don't use ...


wp_generate_metatadata() should create metadata for image, video, and audio file types. There is and if/elseif conditional in the source that limits the function to those three. However, the last line is: return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); So you could use the wp_generate_attachment_metadata filter to ...

Only top voted, non community-wiki answers of a minimum length are eligible