Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Jonas on "wp_schedule_event and delete post"

$
0
0

Hello

First of all: I'm a newbie. This is the first time I code something in PHP. So I need a plugin to automaticly delete posts after 24 hours. Because I couldn't find a plugin with the featrue I need, I decided to code my one one. So I tried something.
In this code I set the time, when a post should deleted. (Maybe it's wrong)
$timestamp = time(); //Gets the seconds since 1.1.1970
$time = date("d.m.Y-H:i", $timestamp); //Formats the seconds in the actual time
$calculateTime = strtotime($time) + 24*3600;  // adds 24h to the timestamp (24*3600=24h)
$FormatedTime = date("d.m.Y-H:i", $calculateTime); //Formats the calculated date

$deleteTime = $FormatedTime; //Sets a better understandabel value.

Next I implemented this:

wp_schedule_event($deleteTime, $daily, do_action('delete_post', 2488));

2488 Is the post ID that I test with. I understand that daly at the $deleteTime the post should be deleted, but it doesn't work.

My second question is:

I'd like that every post in a defined category will be deleted after 24h. So I write something like this. (But it is't true i guess...)

if (in_category(43))
{

//code here
}

Thanks a lot for every help!


Viewing all articles
Browse latest Browse all 8245

Trending Articles