plugin development - Remove tag from all posts when publishing new post

admin2025-06-04  3

I need a function that does the following when a new post is published:

  1. Checks all existing posts and removes the tag "latest" if it exists
  2. 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 );             
  }
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748975209a315304.html

最新回复(0)