=bloginfo('name') ?>
'name', 'order' => 'ASC', 'hide_empty' => true, ] ); // print '
'.print_r($categories,true).''; $display_categories = []; $temp_categories = []; foreach ( $categories as $category ) { // create a new stdObj as opposed to WP's object $new_category = [ 'name' => $category->name, 'slug' => $category->slug, 'cat_id' => $category->cat_ID, 'posts' => [] ]; $posts_args = array( 'post_type' => 'post', 'cat' => $category->term_id, 'posts_per_page' => -1, // gets all posts in this category 'orderby' => 'title', 'order' => 'ASC', 'post_status' => 'publish', ); $category_posts_query = new WP_Query($posts_args); if ($category_posts_query->have_posts()) { while ($category_posts_query->have_posts()) { $category_posts_query->the_post(); $temp['permalink'] = esc_url(get_permalink()); $temp['title'] = esc_html(get_the_title()); $new_category['posts'][] = $temp; } } // separately store stuff we want at the top - to be added to $display_categories later if(in_array($category->slug,$custom_order)) { $temp_categories[$category->slug] = $new_category; } else { $display_categories[] = $new_category; } // Restore original Post Data, needed after running a WP_Query that's in a loop wp_reset_postdata(); } // go through $custom_order in reverse, so we can prepend each one by one onto $display_categories $reversed_custom_order_slugs = array_reverse($custom_order); foreach($reversed_custom_order_slugs as $slug) { if(isset($temp_categories[$slug])) { array_unshift($display_categories, $temp_categories[$slug]); } } //print '
'.print_r($temp_categories,true).''; //print '
'.print_r($display_categories,true).'';exit; ?>