EDIT:
It is currently working when I set a sticky post and set it’s date at 07/07/2016.
My code so far:
I’ve added this to change the post date of the post when it become sticky :
// Update post timestamp
$newdate = current_time('mysql');
$my_post = array(
'ID' => $post_id,
'post_date' => $newdate
);
wp_update_post($my_post);
// Update post timestamp
And also this to unstick the post if it is sticky and older than 7 days :
function deleteOldStickies($post_id, $postDate) {
$postDate = strtotime($postDate);
$currentTime = strtotime(time());
$expire = $currentTime + strtotime('-1 day');
if ($postDate < $expire && is_sticky()) {
unstick_post($post_id);
echo 'Обявата е изтекла!';
}
}
In content.php I call the function as :
<?php echo deleteOldStickies($post->ID, $post->post_date); ?>
My further question from the info above is – am I missing something important, will it work good in live enviroment?