WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like somer code that I can place in my functions.php file that will only modify the specified custom post type.

I have already tried several plugins, but all of them have more features than I need. It's overkill to mess with things I don't want them to mess with.

Ideally, the code will:

  • Set up a daily cron job for 00:00 (at night)
  • Fire a custom function that queries the database for the custom post type and compares its publication date with current date.
  • If the custom post type is older than 3 months (the custom function returns true), then it will call wp_delete_post() for the post's ID.

Unfortunately, I can't put it all together myself.

Is there a good (simple) plugin that does this? A code snippet you have off the top of your head?

share|improve this question

Well there is two ways of doing it in that i can think of...

The simplest seems to be the wp_cron command.


And in your functions you can add some custom SQL (or other) to update your database with whatever you want...

Alternatively you can try this plugin http://wordpress.org/extend/plugins/wp-cron-control/ And make it do you want.

I can't provide the excact SQL you need but with these two you should be able to run scheduled unattended events on your site.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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