I am making an attempt to create a operate that permits me to delete an article when the date of the day is equal or superior than a date crammed in a customized ACF discipline.
I wrote the operate beneath that I positioned in my single.php in an effort to take a look at it. It really works, besides that you just have to be studying the article in query for this operate to execute (fairly logical truly).
What I need is that this operate runs itself on all of the articles, robotically, with out having to go to the articles. That is the place It is tough for me, I typically use plugins to do issues like that.
May you present me some methods to realize the specified consequence? I am actually on the lookout for enhance my back-end expertise utilizing WordPress, so I am not asking particulary for a ready-made answer however methods to information my work.
Here is the operate :
/**
* Draft after expiration
*/
operate draft_the_post(){
$expire_date = get_field( "field_5cef86384e5f2" );
$actual_date = date("d-m-Y");
$postid = $post->ID;
if ($expire_date <= $actual_date) {
wp_update_post(array(
'ID' => $postid,
'post_status' => 'draft'
));
} else {
echo "Not similar date or inferior than at present";
};
}
Oh and, excuse my english I am French 🙂
I thanks prematurely,
willwoody.