Support » Plugins » Hacks » Restoring a trashed custom post via "undo" vs. going to the trash and restoring

  • I’ve got the following action in place:

    	array($this, 'cpt_contact_restore')

    Which executes the following function:

    function cpt_contact_restore() {
    	if(get_post_type() == 'cfe-cpt-contact') {

    This function fires when restoring a custom post via the “undo” link that’s visible right after trashing a post and when going to the trash and restoring it via the action link available under the post title.

    After I added the get_post_type() check, so this function only fires when needed, it stopped working when using the “undo” link, but it continues to work when restoring a post by going to the trash.

    It would seem that both methods of restoring a post should be consistent, if not identical.

    I think the problem is that get_post_type() is not set or something.

    Does anybody have any ideas of what I can do to solve this?

Viewing 1 replies (of 1 total)
  • After a bit more search I noticed that when using the “restore” action link it looks as follows:


    But when using the “undo” link it looks like this:


    So while I still believe that get_post_type() should work in this case as well, I simply added another check for the query string value post_type:

    if(get_post_type() == 'cfe-cpt-contact' || $_GET['post_type'] == 'cfe-cpt-contact')

Viewing 1 replies (of 1 total)
  • The topic ‘Restoring a trashed custom post via "undo" vs. going to the trash and restoring’ is closed to new replies.