Get all image from single page using this query

Use get_children I used this code to extract all the images from a page gallery in the chosen order. you can include this code in the loop or use it stand alone. just choose the appropriate post_parent code (see bellow the code example). This example show all images associated to the page id 1, have … Read more

Set Featured Image Front Frontend Form

you can do that by running the function set_post_thumbnail( $my_post_id, $thumbnail_id ); remember, you have to process and insert the image into the library first: $uploaddir = wp_upload_dir(); $file = $_FILES[ … whatever you have in your POST data … ]; $uploadfile = $uploaddir[‘path’] . “https://wordpress.stackexchange.com/” . basename( $file ); move_uploaded_file( $file , $uploadfile ); … Read more

How do I get attachment_id?

Ok, all those hipercomplex functions can be reduced to one simple command: attachment_url_to_postid You only need to parse the image url to retrieve the attachment id: <?php $attachment_id = attachment_url_to_postid( $image_url ); echo $attachment_id; ?> That’s all you need.

Delete post with all files attached to it

WP does not do this by default since there is no guarantee that attachment isn’t still being used by some other post. Basic logic would be to hook into delete_post, query for child attachments and run wp_delete_attachment() on each. I did quick search in plugin repository and came up with tiny plugin that does just … Read more

Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords

I have tested this with an image I created myself with Photoshop where I inserted the word “Süss” in every thinkable IPTC field. I uploaded it to my WordPress 4.6 installation, which has no image handling plugins installed. The uploading went smoothly, the right thumbnails were created in the uploads directory and the caption field … Read more

remove links from images using functions.php

add_filter( ‘the_content’, ‘attachment_image_link_remove_filter’ ); function attachment_image_link_remove_filter( $content ) { $content = preg_replace( array(‘{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}’, ‘{ wp-image-[0-9]*” /></a>}’), array(‘<img’,'” />’), $content ); return $content; } The regex could be simpler and unfortunately this also deprives you of the unique wp-image-xxx (where xxx is the attachment ID) class of the <img> tag, but it’s the safest one I … Read more

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