How to fetch only media that was already attached to a post/page?
A similar approach to your post_parent idea is to add a filter to posts_where: function bbg_filter_out_non_attachments( $sql ) { global $wpdb; // Maybe do some conditional logic to decide whether to filter this query, then… return $sql . ” AND $wpdb->posts.post_parent != 0 “; } add_filter( ‘posts_where’, ‘bbg_filter_out_non_attachments’ ); Another technique is to do a … Read more