add_action('add_attachment', 'create_post');
function create_post( $attach_ID ) {
$attachment = get_post( $attach_ID );
$my_post_data = array(
'post_title' => $attachment->post_title,
'post_type' => 'post',
'post_category' => array('0'),
'post_status' => 'publish'
);
$post_id = wp_insert_post( $my_post_data );
// attach media to post
wp_update_post( array(
'ID' => $attach_ID,
'post_parent' => $post_id,
) );
set_post_thumbnail( $post_id, $attach_ID );
return $attach_ID;
}
Related Posts:
- How to upload thousands of images?
- Adding Attachment Display Settings in custom media frame
- Redirect to another page using contact form 7? [closed]
- How to upload image with simple form?
- Way to force media uploader use custom image size
- How to make WordPress use protocol indepentent upload files?
- How to extract images of post and pages excluding header and logo image in wordpress?
- Use Media Uploader in Plugin
- Generated Images sizes do not match Media Settings Image Size
- Saving/Writing/Adding file to upload folder
- How to change ID of an attachment in wp_posts and its related tables correctly?
- Get the url of the full sized attachment image using post ID?
- Find unused images?
- wp_generate_attachment_metadata is creating an empty array
- Bulk edit WP posts to update embeded images with new alt tags
- How to upload WordPress Images to remote web server and display those images in WordPress gallery [closed]
- Bulk Image Upload And Rerrange Functionality
- How can I automatically download all images from all imported posts, place them on my new host, and replace all the links
- How to accept images at multiple sizes and aspect ratios and display as standardized image size / ratio?
- download button for audio file in post [closed]
- Large amount image data transfer
- Simple sildeshow/image-upload plugin?
- Copy/paste local images not working in WordPress
- How to change my 3000 Published post status to Draft using PHPMyAdmin
- Is there a way to auto generate poster image for videos
- How to Upload images to a custom folder in upload folder using media uploader
- what functions to use to resize images and create DB metadata for them after/during upload?
- Powerpress upload a podcast without creating a post for it
- Remove special characters from filenames
- Uploading images to custom table
- How to wrap image tag into div for post only?
- flip horizontal images in bulk
- Is there any hook to change media html in post? [duplicate]
- How to force regenerate thumbnails in WordPress posts?
- Retrieve post thumbnails
- How To Convert External Image URLs To Own Website’s Uploaded Images Automatically?
- How Do I Use The WordPress Plugin Posts 2 Posts by Scribu?
- Publish Post After Click On A Link
- Enable comments for post with comments meta box removed
- Edit/revise option for authors to suggest improvement to posts [closed]
- Is there an action that is called when a post is restored from the trash?
- plugin for wp_list_categories with posts
- Replace existing pages with new pages, keep menu links
- Adding “ ” before the last word in multiple defined areas with a plugin
- How to limit 1 image per post on homepage only?
- Flickr plugin that will display photos from multiple group pools? [closed]
- How to add new tabs in post.php
- New post notification plugin [closed]
- Using the “Latest posts” feature on a different site
- Is there a way to order posts and custom post types as one group?
- How can i list random post from multiple category?
- Media upload not working on theme option in WordPress 3.8.1
- Is there an easy way to flag posts in the admin area?
- finding whether request is for post, and post id
- How to allow an editor to edit all WordPress blog posts but have the last say as administrator?
- How generate 200% image size and save with suffix @2x
- Trying to fix form resubmition with PRG (Getting error: Cannot modify header information – headers already sent by)
- transfer a file from one domain to another via wp
- Display wordpress post’s in popup?
- Retrieving Meta from Image Attachment
- Bulk update all posts from plugin settings screen
- Unable to add TAB character to post?
- How to apply lazy loading in background images [closed]
- Woocommerce showing images blurry in description page
- ‘Organize Series Plugin’ as muti author feature
- Is there a way to make the main page only display a brief description of the full article?
- How to Resize the Custom Post Images?
- Images under 1MB are not being compressed
- posts from multiple post types in one slider
- How to display the featured post on the category page?
- Overwrite add_image_size defined by theme
- Renaming Custom Taxonomy Values
- Detect plugin/theme installation (via upload)
- How to get Recent Post From Each Category with Thumbnail?
- Offer Download Links for Product Images
- Why the internal link get converted into a comment?
- Optimal image size for wordpress?
- How to add height and width to images on a page(using WP Bakery) to improve Google’s CLS score?
- Upload PlugIn Button is missing
- unable to write to the database while uploading images
- Access remote SFTP server via WordPress login?
- I need to register and resize images, safe to delete plugin afterwards?
- All Post WordPress Page Error
- Is it possible to create duplicate post on other site (either push, on publish, or pull, periodically)?
- Add dynamic color to each category item
- How to create a dashboard for logged-in users with custom functionality? [closed]
- Publish Post but don’t call publish hook in foreground post creation
- adding image in the header of my dev widget
- How to show post attachment image
- get post excerpt by query
- Advanced Custom Fields (ACF) Plugin – Random Image in Sidebar
- Images not showing and plugins not installing on wordpress server move
- Adding hero images to blog posts
- Is there a WordPress Plugin like Imsanity that keeps high resolution originals? [closed]
- Upload Image to desired directory through plugin
- Images get uploaded itself from the computer
- Shortcode returning specific content of a post
- how to get the url of a custom uploaded file
- A way to upload old html pages with all its assets via WordPress admin and to add a fixed menu on top of those (a la Wayback Machine)
- How to update a lot of posts on my WP site with additional content?