00:00:00
21 Jul

WordPress SQL Query: Select And Delete Posts Between Two Dates

Oliver Krautscheid Apr 08, 2017
0 669

If you are wondering how to delete posts for a certain date, you will need to know how WordPress stores posts in its database.

About Timestamps

In order to delete posts for a certain date we need to have a date, but that alone is not sufficient. WordPress stores the date like this:

2015-06-25 11:53:24

As you can see it includes a timestamp. This goes for post_date and post_date_gmt.

So when you write an SQL query, you have to specify the time like 00:00:00

Select Rows For Regular Posts

Before we actually delete any entries, it’s a good practice to run a SELECT query to verify what it is that you’re getting rid of.

SELECT * FROM wp_posts WHERE post_date > '2015-06-25 00:00:00' AND post_date < '2015-07-10 00:00:00';

Only Select Rows For Custom Post Types

If you have set up your own post type such as “reviews”, “threads”, “products”, we need to further specify the post_type

SELECT * FROM wp_posts WHERE post_type = 'reviews' AND

post_date > '2015-06-25 00:00:00' AND post_date < '2015-07-10 00:00:00';

Deletion

To actually delete the rows, you now only need to drop the statement “SELECT *” and replace it with “DELETE”. If you are entering the query via PHPMyadmin it should then ask you before it runs the query.

Delete From WordPress Posts Custom Post Type.png

About Us

Webmaster .Net is your all-in-one resource for blogging tips, system administration guides, industry news and a growing community of webmasters.

Can't find something or want to tip us?Contact@webmaster.net

Bulls and Bears
Webmaster Tutorials, Wordpress
0 shares669 views

WordPress SQL Query: Select And Delete Posts Between Two Dates

Oliver Krautscheid - Apr 08, 2017

If you are wondering how to delete posts for a certain date, you will need to know how Wordpress stores…

Advertising and Ad Networks, Copywriting
0 shares810 views

15 Tips For Increasing Facebook Ads CTR – Full Guide [2017 Update]

Cam Connor - Mar 30, 2017

In this article, we'll talk a lot about how you can write quality text ads on Facebook Ads to get…

Webmaster Tutorials
0 shares1528 views

10 Steps To Configure Nginx For WordPress, Drop Varnish And Cut Your CPU Load By 50%

Oliver Krautscheid - Oct 10, 2016

Are you using Varnish on your Wordpress blog? Possibly the Varnish script by Unixy? Great! Get rid off it. Here's…

Follow Us And get latest news

© 2016 Webmaster.Net - Property of Peakstone Media Ltd. - All rights reserved. | Privacy Policy | DMCA | Contact Us | Advertise