Get added or removed categories after post update

Question

I developed a plugin, in which I track categories in order to create some additional pages and so on.

If a post has been published or changed to a draft again, I am able to notice this by using the following hook. Therefore, I can compare the old and new status of a post.

This hook is also fired, if I only update the post meta e.g. removing or adding categories.

function run_on_post_status_change($new_status, $old_status, $post) {
    // get the delta between old and new categories, which are assigned to a post
}

add_action('transition_post_status', 'run_on_post_status_change', 10, 3);

How can I get an old and a new “list” of connected categories or how can I get a delta between old and new categories in order to work with it?

For sure, I can check all published categories without children to remove pages or menus which have no corresponding published categorie. But in this case, I have to set up a new database request for categories, menus and pages and I have to compare everything.

0
, , , Rene 7 months 0 Answers 100 views 0

Leave an answer