problem with wp_delete_post
-
Hi
I’m putting together a competition agregation site and having problems with wp_delete_post. THe issue is that it is sending newly published posts directly to trash.
When people add new competitions normally there is no problems with publishing but I wanted the posts to auto-delete once it reaches the closing date. This is the code I use in the single.php file – it is in the loop:
$expirationtime = get_post_custom_values('imwb_socialpress_post_closing_date'); if (is_array($expirationtime)) { $expirestring = implode($expirationtime); } $secondsbetween = strtotime($expirestring)-time(); if ( $secondsbetween >= -10) { blah balh blah, building the post. } else { echo 'Competition closed'; if ( $secondsbetween < -11) { wp_delete_post(get_the_ID()); } }
The way it should work is that when the closing date arrives the first visitor to the page will get a competition is closed notification and the visit should fire off the delete post action.
This does work as wanted except that it sends any newly created posts to the trash also.
If I delete the
if ( $secondsbetween < -11) { wp_delete_post(get_the_ID()); }
Then the posts will publish as expected and when the closing date is reached then the compeition is closed notification appears but obviously the post is not then moved to trash.
I set the $secondsbetween conditional to -11 because I thought there may have been an issue with that but is has no impact on allowing publishing when wp_delete_post is included.
Am I doing something wrong that particularly stands out.
The custom field that I am using for people to store the closing date uses the YYYY-MM-DD format which should be ompatible with the php strtotime function. I am running php 5.3.thanks
Kevin
- The topic ‘problem with wp_delete_post’ is closed to new replies.