I need a function that does the following when a new post is published:
- Checks all existing posts and removes the tag "latest" if it exists
- It adds the tag "latest" the the post being published
This way only the post that was most recently published will have the tag "latest"
So far I have been able to add the tag when a post is published:
function send_new_post($new_status, $old_status, $post) {
if('publish' === $new_status && 'publish' !== $old_status && $post->post_type === 'post') {
$post = get_post();
$id = $post->ID;
wp_set_post_tags( $id , 'latest', true );
}
}