Change number of posts to show on Archive page (custom post type)

Just make sure you’re not in the admin when changing the query:

function num_posts_archive_project_ie($query) {
    if (!is_admin() && $query->is_archive('projects-ie') && $query->is_main_query()) {
            $query->set('posts_per_page', 6);
   }
    return $query;
}

is_admin() does return true only if you’re in the backend (it does not, however, verify that the current user is an admin user, despite the name, don’t let that confuse you), so that hook won’t change anything in the backend post list.

Leave a Comment