I'm using a wordpress custom theme that has this piece of code to prune posts after a number of days (prun_period).

I'm trying to change this to instead prune posts on a certain date. I've created a custom meta field for the expiration date called 'e_date'.

The original code works as intended and looks like this:

if (get_option("post_prun") == "yes" && get_option("prun_period") != "" && get_option("post_prun") != "") {

$prun_period = get_option("prun_period");

$sql = "SELECT `ID` FROM $wpdb->posts WHERE `post_date`<'".date('Y-m-d h:i:s', strtotime("-$prun_period days"))."' AND `post_status`='publish' AND `post_type`='post' LIMIT 10";

$sql = mysql_query($sql);

while ($row=mysql_fetch_array($sql)){

	$post_id = (int)$row['ID'];



	if (get_option("prun_status") == "1") {

		$my_post = array();

		$my_post['ID'] = $post_id;

		$my_post['post_status'] = 'draft';

		wp_update_post( $my_post );

	} else if (get_option("prun_status") == "2") {

		wp_delete_post($post_id);

	}

}

}

?>	

I thought I might be able to just change post_date to e_date and then either delete the part where it subtracts the prun_period or else set it to zero, but it gives me an error.

What I'm asking is if someone can tell me how to tweak that original code to prune on the e_date instead of after prun_period.

Thanks in advance.

    Looks like you'd want to change this:

    strtotime("-$prun_period days")
    

    ...to something with the "prune date" you want to use. If you just want to hard code it:

    strtotime("2009-01-01")
    
      Write a Reply...