I have a site with a custom post. When I enter that custom post in admin (edit)-page then a form is rendered. This form takes like about 2-3s to render – it’s a lot of of values in it – both hidden and not hidden.

When I update this custom post it takes about 2 seconds to update – and after the update it redirects to the custom post and renders the form again, so overall it could take about 8-9 seconds (regeneration of menu, some other stuff that is loaded each time in the wp-admin area).

My question is: Is there any way just to save post data when upate – like hooking ajax-call to UPDATE-button (I really don’t have to reload the page cause it doesn’t change anything)?

UPDATE:
I guess I could something like this (in jQuery)

$( '#publish' ).click( function( e ) {
    e.preventDefault();
    //ajax call to save current postetc.
    //done = alert('post saved');
} );

but would that be right?

1 Answer
1

If all you’re wanting to do is save extra post data you should not need jquery or custom ajax. WordPress has a built in action you can use to achieve this same thing.

add_action( 'save_post', 'save_more_post_meta' );
function save_more_post_meta( $post_id ) {
    //save stuff here
}

If you need help with saving specifics i’ll need a little more detail

Leave a Reply

Your email address will not be published. Required fields are marked *