How to delete orphan attachments?
Try plugin called ‘Media Cleaner‘. It’s seriously made (the author, tigroumeow, mention 5+ time “do a backup before use”) + upload Janitor was last time updated 10 years ago.
Try plugin called ‘Media Cleaner‘. It’s seriously made (the author, tigroumeow, mention 5+ time “do a backup before use”) + upload Janitor was last time updated 10 years ago.
$images = $wpdb->get_col(” SELECT ID FROM $wpdb->posts WHERE post_type=”attachment” AND ID in ($meta) ORDER BY menu_order ASC LIMIT 5 “); Like @Kaiser suggested you can specify a range (5th to 20th results, a total of 15 results are returned at max) like this: $images = $wpdb->get_col(” SELECT ID FROM $wpdb->posts WHERE post_type=”attachment” AND ID in … Read more
Question 1: How do you link Featured Image to its Attachment Page In the loop: <?php if( has_post_thumbnail() ) : ?> <a href=”https://wordpress.stackexchange.com/questions/52394/<?php echo get_attachment_link( get_post_thumbnail_id() ); ?>”> <?php the_post_thumbnail(); ?> </a> <?php endif; ?> Question 2: Post Format Templating Post formats are actually just a custom taxonomy with a fancy UI. Hence, you should … Read more
I’m not quite sure how you’re defining whether or not the current page has only “small” images. But I suspect the answer is right in the wp_get_attachment_image_src function, which returns not just the image url but also the width and height. So let’s say you were only interested in images that are more than 300 … Read more
You can use the function set_post_thubmnail(). After you inserted your post, just call this one, and you are ready to go. $yourpostid = wp_insert_post( $args ); // Define the post in the args first set_post_thumbnail( $yourpostid, $thumbnail_id ); // set the ID of your thumbnail to be the featured image of your newly created post.
In WordPress – Attachments are their own post-type which means you just need to update the post using wp_update_post(): $media_post = wp_update_post( array( ‘ID’ => $attachment_id, ‘post_parent’ => $post_parent_id, ), true ); if( is_wp_error( $media_post ) ) { error_log( print_r( $media_post, 1 ) ); } In the above you would pass both the Attachment ID … Read more
{{ post.thumbnail.ID }} will get you the image ID, but to answer what you’re after…. <img src=”https://wordpress.stackexchange.com/questions/228726/{{ post.thumbnail.src(“medium_16x9′) | default( Image(1234).src(‘medium_16x9’) ) }}”> Reference
I used nextgen gallery plugin to do something like this. Actually I’ve used only half of that: the end user uploads images through the plugin’s interface but the actual display inside the post is done with a custom shortcode. I don’t think there is a way to tell if an attachment has been inserted in … Read more
I have finally figured out how to do it, and it now works 100%!! Plus it uses the admin-ajax.php so clicking the Remove link there is an ajax request sent to the function that does the deleting of the attachment and returns the message saying it has been deleted. Here’s the code for my solution, … Read more
Looks like you may have just not had a loop setup, try this one <div class=”two_images”> <?php global $post; $args = array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘numberposts’ => 2 ); $images = get_posts($args); if ( $images ) { $i = 0; while($i <= 1){ … Read more