Forums

action save_post not firing on create post (4 posts)

  1. patj
    Member
    Posted 10 months ago #

    save_post hook

    I'm writin a plugin which uses custom post types and I've added

    add_action('admin_init','ddb_custom_post_format_admin');
    
    function ddb_custom_post_format_admin() {
    add_action('save_post', 'ddb_save_data');
    .........

    then

    function ddb_save_data($post_id) {
    // try echoing to see what we have
    	echo 'ddb_save_data-post type=' . get_post_type();
    .......

    This works perfectly if I am editing but it doesn't seem to fire at all when adding from the "Add new" menu item of the custom post type.
    The new post of custom post type saves and can be edited OK
    but how can I hook into the save_post of a new post?
    I want to hook into it straight after it has saved so I can do other processing.

    Am I adding the action in the right place?

  2. guldi
    Member
    Posted 9 months ago #

    try publish_post

  3. guldi
    Member
    Posted 9 months ago #

  4. patj
    Member
    Posted 9 months ago #

    Sorted - save_post was firing but the $post variable is not set so a null string was being output. Taking out the bloat and going back to basics sorted it.

Reply

You must log in to post.

About this Topic