Instead of
wp_insert_post($my_post); // create a new post
$post_id = $wp_query->post->ID; // get the ID for the new post
try this:
$post_id = wp_insert_post($my_post); // create a new post
to get the inserted post ID.
Related Posts:
- removing inline styles from wp-caption div
- Add custom Attachment Display Setting for images
- How to get Images included in Post
- disable WP automatically inserted line breaks after an image
- Delete the original big size image after upload and leave only 3 images crunched by media gallery
- How do I detach images from posts?
- upload image in a meta box
- How do I use element instead of tags in WordPress post content having webP support?
- How to remove images from showing in a post with the_content()?
- Unattaching images from a post
- upload featured image from front end using wordpress add media button
- How do I create Comma Separated list of attached image ids?
- Add an image box besides featured image?
- Remove image from post also removes photo from media library
- All my inserted images gets a link to the full image even if it is already full size image
- get custom image size
- Remove permalink from images when inserting into post
- How to get only text from wordpress post content?
- Get all images out of the posts content
- how to replace embedded “full” sized images within a post with the “large” ones
- Batch process: remove first image from post content
- how can I put an image in a post with original size
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Comma separated all attached image ID numbers except featured image ID number
- Modify Image Source With The_Content Filter?
- Load post attached images on a single page site with fancybox
- Errors when uploading images in WP 3.5
- Format the Layout of Images In The Edit Post Textarea?
- Set size for attachments
- I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Get all attachment by post excluding featured and content inside
- wp-cli post create & media import issues
- Get attachments for posts that belongs to a specific category
- Show only posts with images and a fixed amount of posts
- Issue where WP Featured Image will not display
- If statement to check if post has image
- Remove Featured Image & All Media Uploaded to the Post
- What are the benefits of setting a “featured image” for a WP blog post?
- preg_replace not removed “class”
- How to only publish posts with image in it
- Upload attachment from external site
- Get URL from all images in a post
- Disable posts generated from image uploads
- Posts page not showing correct image
- Images showing up in Post Editor, but not in Published Post
- How to allow multiple thumbnail upload for Posts?
- get_children returns older images
- How to display post title inside thumbnail?
- How to remove text and retain in caption image using the_content function
- How to retrieve certain number of images from a wordpress post?
- Hide thumbnail if there is a gallery on the post
- Change the background of each post according to the category
- Where to insert the other site image url for our wordpress post
- select post preview image from nextgen gallery
- Inserting Media to WordPress Posts
- Author Avatar as default first image
- Attachment image single page
- How to change the order of elements within a post?
- Only show featured image on exerpt and exclude images in post
- How to call WordPress First Image Post or else Attached Image or Default
- Regarding Posts
- how can display a post on home screen without images
- Changing The Default Header POST Title and Description text by category in wordpress
- Site/Post preview is not working on all social media
- Delete media from the post but keep my featured image and post
- Pinterest button shows image options from different posts
- How do I fix broken links to images in imported posts’ post_content?
- Thumbnails and images in the blog post are not loading
- Modified core/image rendering not showing in posts – only on pages
- Blog featured images disappeared on my homepage
- Blog images not showing on homepage
- Center crop the feature image
- ‘posts’ table should not store the absolute image path
- How to show category image if no featured image is set?
- How to make an image appear as a thumbnail in the blog post?
- Integrate video and iframe in a post type gallery
- Manipulating images inside post content
- how to create other sizes of original image in one go wordpress uploads
- Output wp_link_pages as raw url
- How can I alternate styling of images in a post? [closed]
- Embed image in post from external url
- Is possible to do this from function.php
- Update all images url imported from HTML pages
- WordPress Media URLs?
- SQL query to remove first image in all posts
- WP Gallery Image Page Issue When 2 galleries share one image
- Post thumbnail dependant on category
- Why can’t I see my attachment page information for an image?
- How would I attach media/images to a post based on a ID stored in a each post’s custom field
- Only show posts with image and the correct ammount of posts in loop
- Assign custom class to post content images
- Extra Theme – Fit image inside of Featured Post Slider
- Is there any SEO impacts on unattached vs attached images for a post in WordPress?
- Full width images within post content
- Import alt text in set_post_thumbnail
- Broken images after importing posts and opening in Gutenberg
- Search doesn’t display posts with images
- Download button under all images WordPress
- website images getting corrupt automatically