Since you are already getting the ID of the newly created post ($post_id
), you just need to get the URL and redirect after the submission.
Using get_permalink( $post_id )
you can get post’s URL. Also, you can get rid of the header()
function to send a new HTTP header, and use WordPress’ own function for redirect – wp_redirect()
.
wp_redirect( get_permalink( $post_id ) );
die();
https://developer.wordpress.org/reference/functions/wp_insert_post/
https://developer.wordpress.org/reference/functions/get_permalink/
https://developer.wordpress.org/reference/functions/wp_redirect/
Related Posts:
- Phantom 302 status code when sending a POST requests on pages
- CF7 upload file failing [closed]
- How to upload post thumbnail while wp_insert_post?
- Downloadable Documents
- How to display comments and comment form on custom post type?
- I am trying to create a simple frontend form for posting
- upload featured image from front end using wordpress add media button
- Display most recent post in category instead of archive?
- How can I fix a slow redirect after form submit from frontend (no plugin)?
- POST from jQuery to PHP
- Redirect before post page
- post_parent is 0 when uploading new files
- How to automate filing a form as a user
- Posts are being redirected to xampp home page
- Why is WordPress redirecting users to random posts after commenting?
- Submitting POST data to a custom page template triggers a 404, why?
- How to get future ID for post which haven’t been created yet?
- Ajax posts filter by date, comments, top views, top likes
- Plain permalinks not working!
- Too many connections to server
- Is it possible to create a form post wordpress custom navigation link?
- creating front end image uploader that uploads images as posts
- Redirection not working in this front end post submission form?
- How to build a site with a map that shows where people offer and need help?
- Relative redirects for posts, categories, products and product categories
- Prevent Delete Attachment by URL or When Submit
- How to convert contact form 7 submission to post after submission? [closed]
- 301 (static page instead latest posts)
- Removal of Media Gallery pictures
- How to get the last selected media alignment setting?
- Set static page/post from another blog on same network
- WordPress Automatic Filename Changer
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- How do I Redirect a WordPress Page?
- Refresh problem post is duplicated when page is submitted after page reload
- Uploading images in custom post form
- Upload attachment from external site
- WordPress 302 Redirect to Random Product/Post/Page
- Post Form Results to Table in Same page
- HTML Form Submit to table in same page
- How to get the form code from the edit page of a specific post?
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- add_rewrite_rule and template redirect not working
- How to call WordPress First Image Post or else Attached Image or Default
- In admin panel, use a form to create a post?
- Standalone form does not post to the url when form fields are populated (otherwise it does)
- How can I to add upload functionality outside of the admin area?
- Creating a redirect option for current page url
- Mailing list submission from a post that doesn’t have a form on it
- How Do I Redirect WordPress Pages but not posts?
- How to let a user create a post by submitting a POST form?
- Cannot create new posts or upload images using media manager
- unable to write to the database while uploading images
- How can I pass form entry to another form on a new page
- Every time I try accessing a post it redirects me to the feed
- Not adding a new post?
- Redirect old Posts URL to new URL
- Redirecting wordpress search query to archive page
- Redirect to custom post if custom archive page has just one result?
- How can I create a Survey Form in WordPress that users can fill in and then submit the entire survey contents as a post?
- Get post attachment with post id
- WP Ajax returning 0, can’t find action
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Submit New Post
- Allow users to post their videos to my wordpress website?
- How to redirect if is post edit or publish page?
- Secretly passing post ID/title etc into a shortcode form automatically to link submission to post
- Why does media_handle_sideload upload to last month’s folder?
- Creating a frontend blog post form for logged in users only
- Ajax the create and edit post form into lightbox and get results
- how to redirect page after delete post inside a post page?
- how to create other sizes of original image in one go wordpress uploads
- issue in wordpress auto delete post and redirect to another 1
- Display result of custom form
- Update all images url imported from HTML pages
- Disable Media uploader to users
- Changing a field value on submit using a PHP variable
- WordPress Media URLs?
- Save/retrieve form data best practises for theme development
- form to post multiple inputs into post_content
- Inserting image into post content – Front End
- User driven content problems
- Redirect posts to sub domain except pages
- How do I insert a custom field in a user submitted post?
- Can’t assign another category other than Uncategorized int he following front end post submission form?
- 301 Redirecting posts without %postid% (just %post_name%) in permalink to ones with %post_name%_%postid%
- Redirecting to a post based on a GET parameter and a custom field
- Get Video Attachment to post
- How can I add a custom caclulation form in post?
- Filter/Sort Post Form On Taxonomy page
- Inserting Media on New Post But Hides Previous Uploads for Editor/Contributor
- What is the proper use of guid for images in wp_posts?
- Post pages are redirecting to the 404 page in wordpress
- Difference between an archive and a page listing posts
- How to embed form data within the ‘Add new post’
- DEL media from the post but keep my featured image or post
- Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
- Can I Paginate Post after every 25 tag?
- Query posts from newest category
- Display only posts with comments