The echo
part should be at the end of your code.
Keep that in mind, any echo or print should be at the end of your piece of code.
<?php
if( $_POST['title_given'] ) {
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags( $_POST['title_given'] ),
'post_content' => 'Did it work??',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'post'
);
// Insert the post into the database
$return_value = wp_insert_post( $my_post, true );
// This echo never appears for some reason
echo "Title given is: " . $_POST['title_given'] . "<br />";
echo "wp_insert_post() returned: " . var_dump( $return_value ) . "<br />";
}
Related Posts:
- Creating a frontend blog post form for logged in users only
- Create posts on user registration
- Create posts without login from frontend
- How to display comments and comment form on custom post type?
- Posts added with wp_insert_post are moved to trash automatically
- I am trying to create a simple frontend form for posting
- Prevent duplicate posts in wp_insert_post using custom fields
- duplicate posts when trying to update a post using the wp_insert_post.
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Custom Post Type & Author not associating, user post count is 0, api doesn’t return author in post objects
- POST from jQuery to PHP
- Phantom 302 status code when sending a POST requests on pages
- generate unique slug while inserting post
- How to automate filing a form as a user
- wp_insert_post works, but the post isn’t visible in the admin post list or front end
- Submitting POST data to a custom page template triggers a 404, why?
- Ajax posts filter by date, comments, top views, top likes
- Email Post Attachment on wp_insert_post Action
- Is it possible to create a form post wordpress custom navigation link?
- post_content sanitization / transformation process
- wp_insert_post – duration
- Redirection not working in this front end post submission form?
- How to prevent duplicate posts with wp_insert_post on single.php?
- How to build a site with a map that shows where people offer and need help?
- CF7 upload file failing [closed]
- How to convert contact form 7 submission to post after submission? [closed]
- Creating a post from data returned from HTML form
- redirect to uploaded (wordpress) post after form submission from front-end
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- post category in wp_insert_post
- When creating a post how do you select the format?
- Refresh problem post is duplicated when page is submitted after page reload
- 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?
- Adding post date will not insert new post
- wp_insert_post not working fine
- Insert data from custom created PHP page into wp_postmeta table
- 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)
- Mailing list submission from a post that doesn’t have a form on it
- How can I pass form entry to another form on a new page
- Not adding a new post?
- Redirecting wordpress search query to archive page
- wp_insert_post() Add and specific ID to the body of that
- Random post_id at wp_insert_post
- How can I create a Survey Form in WordPress that users can fill in and then submit the entire survey contents as a post?
- how to create a category with wp_insert_post and post_category
- WP Ajax returning 0, can’t find action
- Create posts by any logged in users
- wp_insert_post not inserting post
- Secretly passing post ID/title etc into a shortcode form automatically to link submission to post
- Ajax the create and edit post form into lightbox and get results
- Display result of custom form
- Changing a field value on submit using a PHP variable
- Save/retrieve form data best practises for theme development
- form to post multiple inputs into post_content
- User driven content problems
- Insert new post for each user infinite loop error
- 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?
- Get Video Attachment to post
- Is there any point to using wp_unique_post_slug?
- How can I add a custom caclulation form in post?
- Filter/Sort Post Form On Taxonomy page
- Admin notice on wp_insert_post
- Code understanding
- Get WordPress post content by post id
- Get page ID of page that is set as the posts page
- Get Posts Under Custom Taxonomy
- How to limit the number of posts that WP_Query gets?
- Stop WordPress Wrapping Images In A “P” Tag
- When is the ‘post_content_filtered’ column in database cleared by WordPress?
- Turn a URL into an Attachment / Post ID
- GET the excerpt by ID
- Stop WordPress automatically adding tags to post content
- How to update custom fields using the wp_insert_post() function?
- Determine if page is the Posts Page
- How to get ‘post_content’ without stripping tags?
- How to add an admin notice upon post save/update
- Print Current Post Index number within Loop
- Should we trust the post globals?
- Optimize post insert and delete for bulk operations?
- Get the Current Page Number
- How do you add thumbnail support for custom post types?
- How to mark every 3rd post
- Change Posts per page count
- Keep featured content post in homepage with original order
- How to display related posts from same category?
- Can posts have parents?
- Is there a action hook for the “Empty Trash” button?
- How to end the excerpt with a sentence rather than a word?
- How do I check if I linked to a post before I delete it?
- How to change the case of all post titles to “Title Case”
- Appending content with broken in 4.4
- How to get posts published between a date and today?
- ZIP up all images displayed in a [gallery] and offer as download link
- How to detect single.php (but not single-portfolio.php)?
- How to check if post meta key exists or not in wordpress database
- How to remove a column from the Posts page