I have a custom post type table which is connected to the post meta table in wordpress. I need to run some tasks after a post is deleted. For that I use the WordPress hook after_delete_post.
Within my function I need to get access to the user id which is stored by a plugin in the post meta table. I tried to access this meta_value through $post->meta_key but it doesn’t work.
Before I tested it with the wp_trash_post hook where it worked. I don’t understand why I still have access to post->post_type but not to post->meta_key anymore?
add_action( 'after_delete_post', 'my_deleted_post', 10, 2 );
function my_deleted_post($post_id,$post) {
if ( $post->post_type == 'review') {
$meta_value=$post->linked_user_id;
// some stuff to do with $meta_value after post is deleted
}
}