Tweaking Some Code That Pulls a Date from the DB
-
I’m using a 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 WHEREpost_date
<‘”.date(‘Y-m-d h:i:s’, strtotime(“-$prun_period days”)).”‘ ANDpost_status
=’publish’ ANDpost_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” days.
Thanks in advance.
- The topic ‘Tweaking Some Code That Pulls a Date from the DB’ is closed to new replies.