Remove attached media
Remove attached media
Remove attached media
$attachment_id is simply the numerical ID assigned to any media you have uploaded. You can write: echo wp_get_attachment_image(‘1′,’large’); to display the large size of image attachment with ID of 1. You should setup a new query to get all of the attachment IDs associated with the current post, then you can get_posts(‘post_type=attachment’) Check this example … Read more
The problem was that the files wasn’t attached to the post. To make it work I re-attached the files (Media Library > Attach). I also removed the & in $attachments =& get_children( array (.
I am not sure what you mean by “redirect” there. attachment.php is meant to be used as theme template file. Loading it directly it won’t be able to access WordPress core properly. In usual WordPress mechanics you can use get_attachment_link() to form URL itself or wp_get_attachment_link() for whole link HTML.
You need to add the query before the actualy displaying of the div, then you can run your conditional. According to get_posts() it returns an array, so I’m assuming it returns an empty array if posts aren’t found, thus we can check is it’s not ! empty() <?php $args = array( ‘post_type’ => ‘attachment’, ‘orderby’ … Read more
I found a working solution. This handles the uploaded files by attaching them to the post and display them in the loop. Still no featured image is set. if ( $_FILES ) { foreach ( $_FILES as $file => $array ) { $newupload = insert_attachment( $file, $pid_buy ); } } function insert_attachment( $file_handler, $post_id, $setthumb=’false’ … Read more
Although I see this question not specific to WordPress (at least the answer it’s not), I see similar questions posted in a regular basis and I think it is good to give a answer. If a URL doesn’t exist, in your case the URL is for a non-existant attachment, 404 is the correct HTTP status … Read more
Get video attachment ID and display length
I figured out how to retitle the attachment myself, using a combination of the answers from these two posts: How can I add a default description to uploaded files? Change attachment filename Here’s the code, it’s working on my current WP installation (v4.3) function wpse_retitle_attachment( $post_ID ) { $file = get_attached_file($post_ID); $path = pathinfo($file); $args … Read more
So here’s what I did to resolve this… I inserted the following code right after the loop started: <?php global $post; if( is_singular() && is_main_query() && $post->post_type === ‘download’ ) { $download = new EDD_Download( $post->ID ); $files = $download->get_files( ); $submission_attachment_ids=””; if ( is_array( $files ) ){ $first = true; foreach ( $files as … Read more