Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mikeott/d51fa87f477d535176acec48b15fd820 to your computer and use it in GitHub Desktop.
Save mikeott/d51fa87f477d535176acec48b15fd820 to your computer and use it in GitHub Desktop.
WordPress - make specific post always be the latest
/*
Change the date of post ID 946 to the current date.
This is so the post is shown as the latest, thereby showing as the
latest post on the homepage and also as the latest post on the latest-news page.
*/
function update_post_date_daily() {
$post = get_post(946);
$post->post_date = current_time('mysql');
$post->post_date_gmt = current_time('mysql', 1);
wp_update_post($post);
}
add_action('change_post_date', 'update_post_date_daily');
wp_schedule_event(time(), 'daily', 'change_post_date'); /* Runs every day */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment