Code Element Ba

Update WordPress Blog Archive to Display All Posts

There are some instances where you might want to update the WordPress Blog Archive page to display all posts. You can use the pre_get_posts action hook to accomplish this.

/**
 * Update Blog Archive to Display All Posts
 */
add_action('pre_get_posts', function ($query) {
    if ($query->is_home() && $query->is_main_query()) {
        $query->set( 'posts_per_page', -1 );
    }
});