I'm trying to build some functionality where if you're logged into an admin account you'll see a small 'edit' link next to each post title. clicking will use jquery to create 2 form inputs - 1 with the current post title and the other containing the current slug.

I'd ideally like to then allow admins to edit any post/slug from the post page itself using Ajax. To accomplish this I need to find how to update MySQL when the user hits "save". What would be the best way to go about doing this?

I think I'll need to create a new .php file which is called by JavaScript, passing in the title/slug vars. But I'm not sure which Wordpress core files have the SQL code for updating a post title.

Any help would be greatly appreciated!

2 Answers 2


Have a look at wp_ajax action hook for invoking your action. Then use update_post to update the title and slug.

  • oh this is fantastic thanks a bunch. never even knew about this hook and it looks a lot more straightforward coupled with jQuery. Will be testing it out tomorrow :)
    – Jake
    Jun 7, 2012 at 22:58

You need to post your data to the php file from the javascript. In the php file, you need to verify that the user has the authority to change the post title, and then use wp_update_post and change the post_title parameter.

  • yes this looks fantastic! I never even knew about the wp_update_post which allows both the post_title and the URL slug(I think). Will look more into it this evening. Cheers!
    – Jake
    Jun 7, 2012 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.