Your code is flawed. You should never delete posts by issuing SQL directly to the DB. Use WP_Query to find the posts that are duplicates and wp_delete_post to delete them.
Your current method might generate a lot of garbage in the DB.
Side Note: Best way to prevent duplication is not to allow them to be created in the first place.
Related Posts:
- How do I check if I linked to a post before I delete it?
- disable password protected page for logged users
- Dynamically update post title in admin page
- How do I use inline SVG in WordPress
- duplicate posts when trying to update a post using the wp_insert_post.
- Add custom field to all posts in specific category
- Hiding by default specific post status on backend list?
- “Uncaught SyntaxError: Unexpected token
- Displaying Page Title on index.php
- Detect Post Type when publish_post is ran
- WP_Query in functions.php overrides global $post object, even with wp_reset_query()
- Pull posts from another wordpress install on same server
- How can I get all posts data from within a paginated search result?
- Syndicated Posts when Updated Lose HTML tags
- How to insert current date/time in the content of a post?
- How to automate filing a form as a user
- I want to query posts in monthly basis
- Encrypt / Decrypt Post Title and Details
- White Blank Page when Updating and Publishing Page/Post
- Full Width Main Post
- Posts vs. Pages
- Limiting the number of posts in WP_Query leads to unexpected result
- how to set beforsend option in wordpress ajax methods
- Plain permalinks not working!
- Guest Author – How to display posts on /author/ archive page
- How to add pagination in between post and comments?
- Posts not showing on page
- How can I find out what items a user has purchased? [closed]
- Nothing Found error when creating new posts – how to correct this?
- Redirection not working in this front end post submission form?
- Add Word Limit to Posts
- Display multiple custom taxonomy values on single custom post types page?
- How to Programmatically add an empty Block to every post on wordpress site?
- Underscores Theme Unit Testing – Catching Untitled Posts
- How to do set post permalinks using 6 digit random unique function?
- Encountering “Wrong nonce. Action prohibitied.” when trying to alter User Role and unable to Post via WP Admin
- Pulling in post category and children within category
- Is Hfeed class for all pages needed
- get query() without post content?
- Issue where WP Featured Image will not display
- Custom order for Mysql array
- posts_per_page option limits the number of Gallery items
- show custom post type category dropdown sorting result on same page
- Display post category in foreach loop
- Single.php – Get Current Parent Category
- insert a warning message into post-new.php
- WP text editor change html markup
- how can i allow users to view their own pending posts in a front-end page
- How to make different custom post layouts?
- Number of displayed posts
- Modifying the following code to displaying the title and the content of static page Posts page?
- Saving Post Data in Another Database
- singular posts using archive styling
- How can I tell if a post has been published at least once?
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- How to get the form code from the edit page of a specific post?
- Send email for pending post
- Add simple field column to the posts screen
- WP_Query custom field pass the post id
- Get the post id from a plugin
- change the post time on multiple posts
- Making posts permalinks consistent numbers
- How to show category based post in home page?
- Regarding Posts
- Locally change the font family [closed]
- WordPress single.php different layouts projects / posts
- WordPress Post via e-mail writes a random string for the post body
- Add text and change style to post programmatically depending on category
- Permanently deleted posts still exist
- WP_Query outputs wrong post in custom post type
- Export post another site
- Order by meta_key field in WordPress not meta_value field value
- Deleted page still shows and is showing posts archive
- How to show post views shortcode data for each post on Posts List Page?
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- Related Customs posts
- Blog featured images disappeared on my homepage
- Creating a frontend blog post form for logged in users only
- How to hide meta from search result only on pages?
- How do I display posts ordered by a date custom field?
- How to create frontend Post filter using meta query
- How to test if user is filtering post list in dashboard
- Post Format problem
- Post title to show all characters after having it limited for preview
- Custom Select Query pagination not working properly
- Some comment box wordpress in 1 post [closed]
- Template Body to posts
- wordpress paginate, link to the right page
- How to get posts from network blog
- Get current user array with post string
- how to change the permalink to a specific location?
- get next/previous post name
- Get image paths from RSS feeds
- How do I display the next 3 posts in the sidebar?
- 2 tick boxes appearing below comments
- How can to use the players from the Media Widgets in the body of a post to play audio and video files
- How can I display these posts in ascending order?
- Is there any point to using wp_unique_post_slug?
- Polylang – display one post into 3 categories with different lang [closed]
- WordPress + Polylang – Error 404 when trying to preview draft post on different language