Created
November 8, 2016 09:09
-
-
Save gagimilicevic/0fc59268bcf1490acf197001d3628dfe to your computer and use it in GitHub Desktop.
List all custom taxonomy categories (parent and child) and their content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$categories = get_categories(array( | |
'orderby' => 'name', | |
'parent' => 0, | |
'taxonomy' => 'faqs_category' | |
)); | |
?> | |
<?php | |
foreach($categories as $category) { ?> | |
<?php | |
echo $category->name; | |
$terms = get_terms(array( | |
'taxonomy' => 'faqs_category', | |
'hide_empty' => false, | |
'parent' => $category->term_id | |
)); ?> | |
<?php | |
foreach($terms as $term) { | |
$args = array( | |
'post_type' => 'faq', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'faqs_category', | |
'field' => 'slug', | |
'terms' => $term->slug | |
) | |
) | |
); | |
echo $term->name; | |
$query = new WP_Query($args); | |
// Start the Loop | |
while ($query->have_posts()): | |
$query->the_post(); ?> | |
<p><?php | |
echo the_title(); ?></p> | |
<p><?php | |
echo the_content(); ?></p> | |
<?php | |
endwhile; | |
} ?> | |
<?php | |
} ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment