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

Get attachment file link

Well, there is a WP function for that. wp_get_attachment_url It takes attachment id as argument, so you can use it like in following example: echo wp_get_attachment_url( 12 ); This will echo url to attachment which id is 12. You can find more info and examples on Codex page: https://codex.wordpress.org/Function_Reference/wp_get_attachment_url

How to allow specific extensions and file size to wp_mail attachment?

Add the following condition before the file upload functionality – $allowedExts = array(“pdf”, “jpg”, “png”); $temp = explode(“.”, $_FILES[“attachment”][“name”]); $extension = end($temp); if ((($_FILES[“file”][“type”] == “image/pdf”) || ($_FILES[“file”][“type”] == “image/jpg”) || ($_FILES[“file”][“type”] == “image/png”)) && ($_FILES[“file”][“size”] < 1000000) && in_array($extension, $allowedExts)) { //your file upload code and other stuffs } else { echo “Invalid file”; … Read more

Automatically delete attachments and posts [closed]

You can solve your problem with a WordPress Cron Job. I wrote this code and cron scheduler. Also i tested this code on my localhost. If you add this code to your theme’s functions.php you can solve your problem. Cron job and function will work every day and search old posts and their attachments for … Read more

Adding attachment file name to email link

You can get the original attachment filename via wp_get_attachment_url: echo basename( wp_get_attachment_url( $post->ID ) ); or in the form of the example you provided: <a href=”https://wordpress.stackexchange.com/questions/91547/mailto:[email protected]?Subject=Image: <?php the_title(); ?> – <?php echo basename( wp_get_attachment_url( $post->ID ) ); ?>”>Get in touch about this image</a>

Get the size (size in Kb or MB) of an featured image?

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

attachment url rewrite

Actually, you can always just use a query parameter, even if you have the “pretty” permalinks enabled. So instead of /category/sub-category/article.html/attachment/image you can go to /?attachment=image. The only case when this “breaks down” is when you go to /category/sub-category/article.html?attachment=image, because WordPress gets confused: it tries to query for a post and an attachment at the … Read more

Exact image sizes

You’ll want to use add_image_size() in your functions.php to tell WordPress you’d like it to create a new image size when you upload images: add_image_size( ‘custom_image_size_name’, 290, 180, true ); Using the value true will tell WordPress you want it to crop the image to those exact dimensions. Once you do that and upload an … Read more

How to get list of paths (not urls) for an image

This should achieve what you want, however note that there will be backslashes AND forward slashes in the resulting path name. If this causes a problem on your web server you may need to do a further str_replace to forward slashes with backslashes See comments in code for more info $sizes = array_merge(array(‘full’),get_intermediate_image_sizes()); $uploads = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)