I cannot seem to get this to work, I have tried everything I can think of and spent enough time googling, to get me to seek help elsewhere.

I need to query pages in a loop, using the same taxonomy as the current page, but the child term of the current pages term.

For example,

taxonomy = walls
current page term = art

queried pages taxonomy = art
queried pages term= modern-art ( where art is the parent term of modern-art)

I can do this using

$args = array(
  'post_type' => 'page'
  'orderby' => 'menu_order',
  'tax_query'   => array(
            'taxonomy' => 'walls',
            'field'    => 'slug',
            'terms'    =>  'modern-art'

However, I need this code to be dynamic and fetch the data. So I can use the same template of lots of different parent and child terms.


What do you mean by "dynamic" ? Do you want it to work with different posts?

If so, that's simple. Before your get_posts query function, get page terms, and pass them to your array. You can get taxonomies with

 <?php get_the_terms( $yourpostid, 'your_custom_taxonomy'); ?> 
|improve this answer|||||
  • Or You can use ShortCode – yeshansachithak Nov 23 '14 at 9:18
  • Hi there, the idea is that I cannot use a set id ($yourpostid) because this has to be used on multiple pages. So by dynamic I mean that I can use this for different pages with different parent and child terms, if that makes any sense ? For example, still on the walls taxonomy, on another page with a post query, I may have another parent term 'design' with a child term 'modern-design' as opposed to 'art' and 'modern-art'. – user3700046 Nov 23 '14 at 19:57

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.