WordPress.org

Ready to get started?Download WordPress

Forums

Action hooks not working in Quick Edit (3 posts)

  1. stacef
    Member
    Posted 3 years ago #

    I've built an event list plugin that also adds, updates and deletes events in Google Calendar. That interaction occurs using several action hooks, including 'publish_post', 'publish_to_draft', 'draft_to_publish', publish_to_trash', 'trash_to_publish' and so on. And everything works in nearly all scenarios, the exception being Quick Edit changes.

    I've tried the afore mentioned hooks as well as 'save_post' and 'update_post', all of which I'm told should trigger when using Quick Edit. Here's my test code:

    function mytestfunc() {
    	global $post;
    	echo $post->ID;
    	$key = 'test';
    	$data = 'this is a test';
    	update_post_meta( $post->ID, $key, $data );
    }
    add_action( 'save_post', 'mytestfunc' );

    What am I missing here? There must be some way to trigger hooks from Quick Edit mode. Is it a Javascript thing? Any and all help appreciated!

  2. McBoof
    Member
    Posted 3 years ago #

    Same problem here. I can't get save_post to fire when using Quick Edit. Help?

  3. havahula
    Member
    Posted 2 years ago #

    don't know if you are both relying on global $post but when editing inline, it doesn't appear that the global $post object is available so, you'll likely need to set that variable manually like so: $new_post = get_post( $post_id ), where $post_id is passed by the hook to your function. so, stacef, your function would look like this:

    function mytestfunc( $post_id ) {
    	$new_post = get_post( $post_id );
    	$key = 'test';
    	$data = 'this is a test';
    	update_post_meta( $new_post->ID, $key, $data );
    }
    add_action( 'save_post', 'mytestfunc' );

    of course, if you're checking for nonces and whatnot, you'll need some additional conditionals to handle that but, essentially, this should get you what you want.

    One caveat -- you will be receiving the updated post data so, if you were hoping to grab the pre-updated post data you'll need to pull that from the $_POST array.

    hope that helps!

Topic Closed

This topic has been closed to new replies.

About this Topic