Wordpress submit post content from front-end with Ajax

admin

Administrator
Staff member
I am generating my own Wordpress template and would like to give users a front-end form (so they don't have to log in to the wordpress dashboard) to submit some post content. I've got everything working, thanks to <a href="http://wp.tutsplus.com/tutorials/creative-coding/posting-via-the-front-end-inserting/" rel="nofollow">this tutorial</a> - but I'd like to make one enhancement. Currently when the user presses submit the data is stored in wordpress and they are then redirected to a fixed URL of my choosing. Rather than this I would like to simply clear the form data and display a confirmation message - I guess via AJAX? I know there are built in AJAX capabilities in wordpress, but I've never really used it. Can anyone help me out?

The part of the code that submits the data to Wordpress and provides the URL to be redirected is copied below. I assume I wil need to make a change here?

Code:
$post_id = wp_insert_post($post_information);

if($post_id)
{
    wp_redirect( '/thanks' );
    exit;
}