How to order WP_Query to group results?
If your naming system is consistent then simply ordering by the post name should do it: $args = array( ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ); $q = new WP_Query($args); var_dump($q->request); var_dump(wp_list_pluck($q->posts,’post_title’)); Or, as a pre_get_posts filter (assuming the main query is what we want to alter): add_action( ‘pre_get_posts’, function ($qry) { if ($qry->is_main_query()) { … Read more