Title: when before_delete_post hook, get_permalink failed
Last modified: May 14, 2021

---

# when before_delete_post hook, get_permalink failed

 *  [laowang1](https://wordpress.org/support/users/laowang1/)
 * (@laowang1)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/when-before_delete_post-hook-get_permalink-failed/)
 * when before_delete_post hook, get_permalink failed,
    it return mydomain.com/?
   p=11111
 * but when edit_post hook, get_permalink return correct permalink url.

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

 *  Thread Starter [laowang1](https://wordpress.org/support/users/laowang1/)
 * (@laowang1)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/when-before_delete_post-hook-get_permalink-failed/#post-14436726)
 * How can I get correct permalink url in before_delete_post hook?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/when-before_delete_post-hook-get_permalink-failed/#post-14439735)
 * Well, p=1111 style is a valid link to the post 🙂 But not following your defined
   permastruct. Your callback is passed the post’s object. You could construct your
   permalink using your own code and the object’s data. Exactly how depends on what
   your permastruct is. On a basic level, just append the post’s slug to your site
   URL.
 * For more flexibility, the permastruct is stored in the “permalink_structure” 
   option. You’d then replace all %tags%-like elements in the structure with their
   proper values for this particular post.
 * It probably doesn’t matter, but out of curiosity, why get the permalink of a 
   post that’s going to be deleted?
 *  Thread Starter [laowang1](https://wordpress.org/support/users/laowang1/)
 * (@laowang1)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/when-before_delete_post-hook-get_permalink-failed/#post-14443618)
 * I need permalink to get local cached static file path to delete them.
    I found
   a way to fix that, just disable TRASH, add below line to wp-config.php define(‘
   EMPTY_TRASH_DAYS’,0);

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

The topic ‘when before_delete_post hook, get_permalink failed’ is closed to new 
replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [laowang1](https://wordpress.org/support/users/laowang1/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/when-before_delete_post-hook-get_permalink-failed/#post-14443618)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
