Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
    
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 Rocheleau Jun 7 '12 at 22:58
add comment

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.

share|improve this answer
    
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 Rocheleau Jun 7 '12 at 23:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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