Performance: Post scheduling and status
This affects the timing of content visibility and server load during page rendering and publishing.
Jump into concepts and practice - no test required
<?php // Use WP_Query with post_status to get only scheduled posts $scheduled_posts = new WP_Query(array( 'post_status' => 'future', 'posts_per_page' => 10 )); ?>
<?php // Query all posts and filter by date manually $all_posts = get_posts(array('numberposts' => -1)); foreach ($all_posts as $post) { if (strtotime($post->post_date) > time()) { // Show as scheduled } } ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual filtering of all posts for scheduling | High (loads all posts) | Multiple (due to slow server response) | High (delayed content) | [X] Bad |
| WP_Query with post_status = 'future' | Low (only scheduled posts) | Single reflow | Low (fast content load) | [OK] Good |
future status is specifically for posts set to publish at a later date.future -> Option Afuture status [OK]wp_insert_post?post_status.'draft'.post_date to a future date but post_status to publish when inserting a post?post_date and post_statuspost_date is in the future, WordPress changes status to future automatically.post_status is set to publishpublish to future for future dates to schedule the post.future -> Option Dpost_date set to a future time but it publishes immediately. What is the most likely cause?post_date with current time using site timezone.post_date_gmt usagedraft status causes immediate publishpost_status and post_date should you use?post_date to tomorrow 9 AM; "keep as draft" means no auto-publishing, so use post_status = 'draft'.post_date; future dates do not trigger auto-publish.post_status = 'draft' with post_date tomorrow: stays draft now, dated tomorrow when manually published.post_status = 'draft' and post_date set to tomorrow 9 AM -> Option Cpost_date = draft with future date [OK]