Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having some trouble with scheduling posts to automatically expire (either by deleting or going to draft), every plugin I have tried does nothing and when it reaches the scheduled time nothing happens, which is making me think its probably some simple thing I keep overlooking..

I thought I might be a problem with wp-cron, but I don’t seem to have any trouble setting up a publish date in the future through wordPress.

I have the latest version of Wordpress running, with multi-sites set-up. All plugins were at the latest version available at the moment.

Does anyone have any ideas?? I am running out of things to try...

Thanks in Advance

Tafts

share|improve this question
    
NOTE: when using the plugin Content Scheduler, in the column for the expiry status the default is (Expiration Disabled) but when I enable it with a date nothing shows up, just a blank space, rather than the expiration date ... not sure if this might help –  Tafts Mar 1 '11 at 5:54

2 Answers 2

create for these posts a customfield with the name expires and the value is the date for disabling the post. Use the following code in the Loop of your theme.

//Loop-Start
if (have_posts()) : while (have_posts()) : the_post();
  $exTime = get_post_custom_values('expires');
  if (is_array($exTime)) {      
  $exString= implode($exTime);
  $seconds = strtotime($exString) - time();
} else {
  $secondes = 1;
}
if ($seconds > 0) {
  echo "<h2>";
  the_title();
  echo "</h2>";
  the_content();
}
endwhile;
endif;

This code wont delete or drafting the posts. But you don't see it in the front. Perhaos this is a possible solution for your problem?

share|improve this answer
    
I had also tried hard coding it using a similar code and setting the date with custom values, still no luck –  Tafts Mar 2 '11 at 0:53
up vote 1 down vote accepted

I got it working using the Post Expirator plugin, which also had the same problem, but by adding the following code to each loop right after 'the_post();' it checks the posts status on each page load, it is a temporary solution which seems to work for the moment.

// check to see whether post has expired
$expiration = get_post_meta($post->ID, "expiration-date", true);
if ($expiration && (time() > $expiration)) {
    $postSettings = array(
        'post_status' => 'draft'
    );

    wp_update_post($postSettings);
} else {
// normal content goes here
}
share|improve this answer

Your Answer

 
discard

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.