0

So I have a custom taxonomy of continent which is linked to a custom post type of offices.

Under the continent category I have:

Europe
-- Germany
----- The Posts
-- United Kingdom
----- The Posts
Asia
-- Australia
----- The Posts
-- New Zealand
----- The Post

Ideally I'd like the HTML to look something like:

<h2>Europe</h2>
<h3>Germany</h3>
<ul>
<li>The post</li>
</ul>

What's the best way to go about this? I've been struggling to get the sub taxonomy and then get the posts.

Sorry if this question has already been posted, I couldn't find anything but I could be wrong.

Thanks in advance!

1

You can use tax_query for this purpose.

$the_query = new WP_Query( array(
'post_type' => 'offices',
'tax_query' => array(
    array (
        'taxonomy' => 'europe',
        'field' => 'slug',
        'terms' => 'germany',
    )
),

) );

You can also use more then one term in this query.

  • Thanks, how could i get this into one big loop to loop through each taxonomy? – Will Beeching Nov 7 '17 at 12:37
  • You can use get_taxonomies( ) function to get all taxonomies and loop through this array. – wpdd Nov 7 '17 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.