WordPress.org

Ready to get started?Download WordPress

Forums

action save_post not firing on create post (4 posts)

  1. PatJ
    Member
    Posted 2 years 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 2 years ago #

    try publish_post

  3. guldi
    Member
    Posted 2 years ago #

  4. PatJ
    Member
    Posted 2 years 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.

Topic Closed

This topic has been closed to new replies.

About this Topic