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?
- WP galleries in posts after import. How do I do it?
- Where Should i write the code for wordpress ajax voting?
- How to get images using taxonomy ( WP Media Folder)
- adding Adsense’s In-Article Ads between images of blog post
- Add “Featured Image” box in my plugin post page
- check uncategorized category by default
- Print posts category or tag as a formatted journal
- how to execute some code after a post is published in WordPress [duplicate]
- Post status doesn’t update to ‘future’ every time?
- Blurry images when loading the page first time
- Function added to hook “new_to_publish” not executing – custom plugin
- Get Image Having the ID [closed]
- Image Galleries for website migrated from .com to .org
- Search by Attachment ID
- File Uploader – Upload without adding to Media Library
- Creating an admin meta box to save post as pending
- trigger email when post is published by someone a user follows
- Grab ID from post from plugin and use it to create an object
- How programatically cause uploads folder to be created?
- Article content navigator in wordpress like mbaskool website
- Issue with wp_handle_upload
- WP::is_main_query() Not Working
- Overwrite add_image_size defined by theme
- Scrape a webpage for image and add it to post
- I would like to remove date display on photo preview
- JSON API Plugin not showing Attachments id reused
- Post deleted in trash [closed]
- Renaming Custom Taxonomy Values
- Getting a list of the published posts
- How to relate 3 wordpress components with each other (Create database relationships)
- Change website directory safely to add a static page on startup
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- How do I link an image in my plugin so it displays on WordPress?
- If post exists in the database – each time goes on `else`
- Custom Template for wordpress cpt plugin
- Embed PDF into wordpress
- Hook Scripts and Styles in WordPress
- Get data from wp_posts of mysql in to variables of wordpress-php script
- WordPress plugin: Getting posts where checkbox selected
- Detect plugin/theme installation (via upload)
- What hook can I use to modify custom post data before it is displayed on the page?
- get current page number with wp_link_pages()
- problem with register_activation_hook in plugin
- Add a file upload field
- How can i summerize posts or news automatically in word press site?
- WordPress “Add new tag” button is not working
- Delete data from custom table when deleting a post
- How to auto strip hyperlinks & images in wordpress post
- How To Create A File Archive in WordPress?
- how can authors to define custom pages?
- Plugin is creating posts twice
- Some images on WordPress site are suddenly gone
- Regenerate Thumbnails Plugin successfully updated my thumbnails but image src won’t change to new image size?
- Add_image_size not generating correct size
- Is there a way to insert multiple images into a post at the same time without using a gallery?
- Is there a Image Gallery which will load all my posted Images like twitter’s image grid?
- Multiple images per post – Show random image elsewhere
- Edit part of a post
- How to write a new file when new post has been published in WordPress
- WordPress Stats Plugin: Display Post Views [closed]
- WP Editor, save content and category on frontend
- Replace image urls(absolute instead of relative) by using filter in single page
- Plugin for TinyMCE to create reference to other posts
- How to call WordPress First Image Post or else Attached Image or Default