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);
}
Related Posts:
- How to add/assign or change featured image in post programmatically?
- Force update all posts in custom post type, no content changes
- IP camera jpg stream to post
- Send a review notification email to admin when a post is 12 months old
- How can I post exact same post but with a few things changed? (with some sort of Automation)
- New Gmail email to a WordPress new post? [closed]
- Automate post update for all posts?
- How to select a category automatically based on a word in WordPress post title?
- How to delete posts with incorrect status
- Is it possible to Schedule Attachments in WordPress?
- Is post ID number always incremental n+
- post__in for get_posts with a dynamic array
- Check if post has children or not
- Create custom page in WooCommerce
- Duplicate posts
- How to hide a post from ‘Recent Posts’ widget?
- Hide add new page button
- get_next_post() not working
- Create a separate JS application for an individual post?
- post_parent is 0 when uploading new files
- custom post type grid with content in lightbox [closed]
- Divide Loop Into Days & Categories
- Search for posts based on their url in the admin?
- “next_posts_link” and “previous_posts_link” display me NOTHING
- Can I set and show “important” post in my blog?
- Add Post Tags to Body Class
- WordPress – Hide posts in admin from user who did not write them
- Understanding and using metaboxes in posts
- How to display different number of posts
- What part of template to edit to remove category name from the top of posts?
- Register post status, exclude from searches
- How to give capability (publish contributors posts) to author role?
- Ajax Dynamic Archives not showing correct results
- Load post attached images on a single page site with fancybox
- How to make a price range slider from get_post_meta?
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Prevent Delete Attachment by URL or When Submit
- Non-existant URL redirects to existant one
- How to Next and Prevous Navigation Buttons on the end of the page with custom image Using Wp Post Navigation Plugin
- pagination for single post by category
- Post page to display specific category
- Calling Different Custom Post Timestamps in a table
- Exclude the first ‘n’ number of posts of a tag from home page?
- how to show single post in a custom template
- How do I change the core post search algorithm? Where is it found/constructed?
- wp_posts table: safely remove unused columns to save database storage
- how to get random post id by using post type
- Remove current category from post but display all others
- How to get links to the last N posts in a specific category?
- wp_update_post question on array
- How to only publish posts with image in it
- Why won’t pagination work?
- Single post page breaks when post is more than 30,000 words
- Front end post submission form with duplicate type fields
- How to add some html formated text to every new post in WordPress
- Using system date format
- Posts and Pages: 404 Page not found
- WordPress post next/prev not working
- Auto update post title and slug when post status is changed
- When sending a newsletter -not with wordpress- the server has 100% cpu [closed]
- Post titles and thumbnails as links to custom post types?
- get last post’s link with SQL query
- Output Buffer Issue with Single Post View
- show div only if have a related post inside
- changing parent_id on post
- How do I apply a template to my single posts?
- Help Combine These Two PHP Codes
- How to display list of results
- Some blog posts containing source code fail to save draft or publish
- How Do I Redirect WordPress Pages but not posts?
- Post count doesn’t match number of posts shown in list in admin
- Problem paginating a subquery on a post
- How to setup default value of post_id
- Display post by Random Authors on Page Refresh
- Count singular post views automatically
- Pagination (on the static front page) shows always the same posts
- Loop and output 4 rows of posts on home page
- Bulk Post update_post_meta
- Loop through all posts showing duplicates
- Embed image in post from external url
- Code works on a page but not in a widget
- List posts of assigned categories in list of all categories on single.php
- Display result of custom form
- How can I choose and change a post title at random from an array when it is published?
- Post/Edit/Delete Post From Frontend… How?
- How to show the posts list into a static page? Problems to use the loop into a static page
- Get post title by Alphabet
- Make a paginated article (for easier reading on mobile)
- WordPress post text starts newline after 93 characters
- new blog post does not appear in blog after publishing
- wordpress taxonomy results
- Deleting first four characters from all Post Titles
- Deleling wordpress posts permanently still have IDs
- wp trim function not working
- Custom post page has attributes of latest post [closed]
- Can I get custom post items in select box (dropdown)
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- Import alt text in set_post_thumbnail
- Need to show birthday of custom post type(Famous people in this case) in elementor. Date of birth set in custom fields