Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Created November 8, 2016 09:09
Show Gist options
  • Save gagimilicevic/0fc59268bcf1490acf197001d3628dfe to your computer and use it in GitHub Desktop.
Save gagimilicevic/0fc59268bcf1490acf197001d3628dfe to your computer and use it in GitHub Desktop.
List all custom taxonomy categories (parent and child) and their content
<?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