post_type == 'faq') { if (get_field('faq_page_title', 'option')) { $context['heroTitle'] = get_field('faq_page_title', 'option'); } else { $context['heroTitle'] = $post->title; } $context['heroContent'] = get_field('faq_subtitle', 'option'); // Get Categories with hierarchy $cat_args = array( 'taxonomy' => 'faq_categories', 'order' => 'ASC', 'hide_empty' => false, 'hierarchical' => true, ); $categories = get_terms($cat_args); $count = 0; $categories_array = array(); foreach ($categories as $cat) { // Check if Taxonomy is top level tax if ($cat->parent == 0) { $i = 0; $categories_array[$count]['title'] = $cat->name; $categories_array[$count]['side_nav_title'] = get_field('side_nav_title', $cat); $children = get_term_children($cat->term_id, 'faq_categories'); // If Tax has children if ($children) { foreach ($children as $child) { $post = get_term($child, 'faq_categories'); $categories_array[$count]['children'][$i]['title'] = $post->name; $categories_array[$count]['children'][$i]['side_nav_title'] = get_field('side_nav_title', $post); $categories_array[$count]['children'][$i]['posts'] = new PostQuery([ 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'faq_categories', 'field' => 'id', 'terms' => $post->term_id, ), ) ], FAQ::class); $i++; } } else { $categories_array[$count]['posts'] = new PostQuery([ 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'faq_categories', 'field' => 'id', 'terms' => $cat->term_id, ), ) ], FAQ::class); } } $count++; } $context['categories'] = $categories_array; $context['faqs'] = new PostQuery([ 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => 'ASC', ], FAQ::class); $context['about_the_program'] = new PostQuery([ 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'faq_categories', 'field' => 'slug', 'terms' => 'about-the-program' ), ) ], FAQ::class); $context['about_your_company'] = new PostQuery([ 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'faq_categories', 'field' => 'slug', 'terms' => 'about-your-company' ), ) ], FAQ::class); $context['eligibility_and_admissions'] = new PostQuery([ 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'faq_categories', 'field' => 'slug', 'terms' => 'eligibility-and-admissions' ), ) ], FAQ::class); $context['get_in_touch_faq'] = new PostQuery([ 'post_type' => 'faq', 'post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'faq_categories', 'field' => 'slug', 'terms' => 'get-in-touch' ), ) ], FAQ::class); // // // Array to be used later // $faqCategoriesArray = array(); // // // Store categories in variable and also pass into Twig context // $categories = get_terms( array('taxonomy' => 'faq-category', 'hide_empty' => false) ); // $context['faq_categories'] = $categories; // // // Loop through each of the Categories // foreach ($categories as $category) { // $slug = $category->slug; // // Get FAQs // $faq_args = [ // 'post_type' => 'faq', // 'post_status' => 'publish', // 'posts_per_page' => '-1', // 'orderby' => 'ASC', // 'tax_query' => array( // array( // 'taxonomy' => 'faq_categories', // 'field' => 'slug', // 'terms' => $slug // ) // ) // ]; // $faqs = new PostQuery($faq_args); // foreach ($faqs as $faq) { // $faqCategoriesArray[$slug]['faqs'][] = $faq; // } // $faqCategoriesArray[$slug]['slug'] = $slug; // } // $context['faq_posts'] = $faqCategoriesArray; $template = 'faq.twig'; } if ($post->post_type == 'companies') { if (get_field('companies_page_title', 'option')) { $context['heroTitle'] = get_field('companies_page_title', 'option'); } else { $context['heroTitle'] = $post->title; } $context['heroContent'] = get_field('companies_subtitle', 'option'); $context['companies'] = new PostQuery([ 'post_type' => 'companies', 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => 'ASC', ], Companies::class); $template = 'companies.twig'; } Timber::render([$template], $context);