Created
June 12, 2023 02:19
-
-
Save mikeott/d51fa87f477d535176acec48b15fd820 to your computer and use it in GitHub Desktop.
WordPress - make specific post always be the latest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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