Get attached media only

All media (somewhat incorrectly) in the $wpdb->posts table will be “attachments” whether actually attached or not. “Attachments” that are actually attached will have a post_parent other than 0, so what you need are all of the attachments that have a 0 in the post_parent column, if I understand you. $args = array( ‘post_type’ => ‘attachment’, … Read more

How do I create Comma Separated list of attached image ids?

You can try this one-liner, within the loop, instead of all your above code: $ids = join( ‘,’, wp_list_pluck( get_attached_media(‘image’ ), ‘ID’ ) ); where we pluck out the ID’s from the get_attached_media() output. Another approach would be to use: $ids = join( ‘,’, get_attached_media( ‘_image_ids’ ) ); where we’ve introduced a new input parameter … Read more

Allowing post attachments without allowing to insert in text

One way to do this would be to simply hide the upload/insert media button: and, then add featured image support for your themes posts, so a user can still attach images to the post. Hide upload/insert media button for your theme in: functions.php: function hideUploadInsert($hook) { if($hook != ‘post.php’ AND $hook != ‘post-new.php’) return; // … Read more