Can I attach an image to a different post?
This works for me: http://wordpress.org/support/topic/detach-amp-re-attach-media-attachment-images-from-posts#post-1609173 I’ve saved this as a snippet in my IDE for use in projects. Very handy!
This works for me: http://wordpress.org/support/topic/detach-amp-re-attach-media-attachment-images-from-posts#post-1609173 I’ve saved this as a snippet in my IDE for use in projects. Very handy!
Regex to turn embedded images in to attachments
This is a problematic idea. WordPress do not have any strong connectivity between an image (or any other uploaded file) and any content (post). This means that in theory you can not make a decisions like if it is an image on page do X as nothing ensures you that the image will not be … Read more
Here is my working solution. The code is documented, so it should be clear what each function does. I pretty much use the wp_generate_attachment_metadata filter to create the needed images after the image has been uploaded. The generated images are listed in the metadata too, like any other intermediate image size. That way you can … Read more
The issue is that WordPress always maintains the aspect ratio on your photos. For a lot of uses, this makes sense. However, if you’re trying to line up a bunch of images — some in portrait, others in landscape — it can be a real pain. If you want to fix this, you can register … Read more
You can use get_attached_file() to: Retrieve attached file path based on attachment ID. And get_post_thumbnail_id() to determine the post thumbnail of the current post, or any post if you set the $post_id parameter. Exemplary usage: $bytes = filesize( get_attached_file( get_post_thumbnail_id() ) ); Use size_format() to Convert a given number of bytes into a human readable … Read more
Looking at @obmerks answer on https://stackoverflow.com/questions/12997698/delete-images-after-post you can simplify it with this: foreach ( $productIds as $productId ) { $child_atts = $wpdb->get_col(“SELECT ID FROM {$wpdb->posts} WHERE post_parent = $productId AND post_type=”attachment””); foreach ( $child_atts as $id ) wp_delete_attachment($id,true); } Note: as per documentation https://codex.wordpress.org/Function_Reference/wp_delete_attachment set the second parameter to true to force delete the attachment, … Read more
You need the bulk image resize utility: http://wordpress.org/extend/plugins/bulk-image-resize-utility/ I have used that numerous times and it does a fantastic job!
Finally by luck i found the answer by @Tomas function gallery_template_to_posts() { $post_type_object = get_post_type_object( ‘post’ ); $post_type_object->template = array( array( ‘core/gallery’, array( ‘linkTo’ => ‘media’, ) ), ); } add_action( ‘init’, ‘gallery_template_to_posts’ );
A little background: WP stores the attachments in the same database table as posts. Therefore the table rows correspond to the fields of the media edit modal: get_post_gallery_images will return you URLs to the images, but not the actual data in the database. You could do a reverse-query and look for posts that contain the … Read more