admin - Is it possible to hook AJAX to UPDATE-button?

admin2025-01-07  4

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?

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?

Share Improve this question edited Sep 3, 2014 at 19:33 kaiser 50.8k27 gold badges150 silver badges244 bronze badges asked Sep 3, 2014 at 18:48 bestprogrammerintheworldbestprogrammerintheworld 1,3212 gold badges19 silver badges40 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736259544a597.html

最新回复(0)