Link Featured Thumb to Attachment Page, If Possible

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

wp_insert_post featured image from library

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.

How to grab the first two image attachments from a post?

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

why when I try to insert an image attachment along with a post does wp_get_attachment_url give me a very wrong file path?

It turns out I was barking up the wrong (or at least a slightly different) tree by using wp_insert_attachment. media_sideload_image managed to pull attachments from other blogs on the same multisite install, copy them to the aggregating blog’s uploads directory, and generate thumbnails, while wp_insert_attachment was doing what it was supposed to, which just happened … Read more

Delete all thumbnails for a post

Using wp_delete_attachment( $attachmentid, true ) is only thing you need. Passing true as second argument, ($force_delete see codex ) it: remove the thumbnail association with any post delete any taxonomy associated to attachment and of course remove all the files, also the autogenerated ones So you do not need to also use delete_post_thumbnail().