wp_trash_post seems to only work on posts and not on pages or cpt
Yes… I figured that out. I guess my question wasn’t clear. Is there another hook that will work for CPTs, or do I have to create a custom one?
“wp_trash_posts” fires on the trashing of any post, page, or CPT on my site. It should on yours too. If it is not, some other code has hooked into the process in a way that prevents your callback from being called. To narrow down what code is doing this, do the deactivate all plugins and use a twenty* theme troubleshooting process.
Thanks @bcworkz! It wasn’t another plugin conflict… but your response got me thinking about a conflict in my own plugin, which I hadn’t thought of before.
The issue was that I have two functions – one that creates data in an API, and one that deletes that data from that API. But I was having the create function run with the save_post hook, which I now know runs any time a change is made to that post, including when the post is trashed. So when I trashed the post, both the delete and create functions ran, which resulted in no change to the data. I replaced save_post with publish_post and all is working properly now.
Thanks for the help!