0

Is it possible to delete/move to trash a post in a single category each time that a new post in the same category is created? I mean, I need to always keep just one post (the most recent) visible in that one category.

0

Why not. The API of WordPress has the function wp_delete_post to delete a post. If the trash is active, on default true, then this function moves the post to the trash. You need to add a logic after publishing a new post to delete the old one. To firte your function you should use the hook publish_post.

So a simple starter see below, need the logic to get the ID of the old post.

add_action( 'publish_post', 'post349197', 10, 2 );
function post349197( $ID, $post ) {

    // &oldID = Need logic to get the last post.
    wp_delete_post($oldId);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.