• Resolved Kazi Mohammad Foysal

    (@kmfoysal06)


    Hi, I Want To Call Function When My Reserved Post Type is Modified So I Used save_post Hook and I Completed Everything But After I Found This Bug That When I Move The Post It Call The Save Post Hook But I don’t Want This.I Want This For Only When The Post Is Inserted or Modified. I Tried With wp_insert_post And Tried $post->post_status !== ‘trash’ And $_[‘POST’][‘action’] !== ‘trash’ But It Don’t Work.The Hook Is Triggered When I Try To Move The Post In Trash .

    add_action("save_post", [$instance,'save_metabox'],10,3);

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • threadi

    (@threadi)

    Moving a post to trash is also a change, so the hook is also used. If you do not want your application to be processed in this case, check the status of the post within your function.

    Moderator bcworkz

    (@bcworkz)

    Agreed, checking status is what you should to. FWIW, you could use the dynamic action hook `“{$old_status}_to_{$new_status}” to only call your callback for specific status changes like “draft_to_publish” and “publish_to_trash”.
    https://developer.www.ads-software.com/reference/hooks/old_status_to_new_status/

    Thread Starter Kazi Mohammad Foysal

    (@kmfoysal06)

    @bcworkz and @threadi , thank you for providing your valuable time for this issue. I have fixed this in another line where I was verifying the nonce. Initially, I was using wp_die() to confirm that the nonce is verified. However, when I changed wp_die() to return;, the function was not being called when I moved the post into the trash.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘save_post Hook Firing When I move the post on trash’ is closed to new replies.