How do i upload an image and return the image id?

Take a look at side loading images. media_sideload_image()/wp_handle_sideload() and get the ID from the URL. attachment_url_to_postid. <?php $url = “http://wordpress.org/about/images/logos/wordpress-logo-stacked-rgb.png”; $title = “Some Image Title”; $alt_text = “Some Alt Text”; require_once(ABSPATH . ‘wp-admin/includes/media.php’); require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/image.php’); // sideload the image — requires the files above to work correctly $src = media_sideload_image( $url, … Read more

how to test for attached image

function has_image_attachment($post_id) { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image/jpeg’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post_id ); $attachments = get_posts($args); if(is_array($attachments) && count($attachments) > 0) { //Has image attachments return true; } else { return false; } }

Creating a multi-file upload form on the front end for attachments

This may not be the most elegant way to do it (I’m not sure if overwriting the $_FILES global is even allowed) but this seems to work: global $post; if ($_FILES) { $files = $_FILES[‘upload_attachment’]; foreach ($files[‘name’] as $key => $value) { if ($files[‘name’][$key]) { $file = array( ‘name’ => $files[‘name’][$key], ‘type’ => $files[‘type’][$key], ‘tmp_name’ … Read more

Moving image attachment from post to another?

As far as I know, you’d have to use a combination of built-in functions to achieve this. If there is a plugin, you’d have to research for “Bulk parent” or “Bulk re-attachment”. Unless you have a logic connecting those posts, I think you’d have to do it post by post. Be it with PHPMyAdmin (changing … Read more

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