Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Punal Chotrani
Punal Chotrani
8,817 Points

How do i display custom taxonomy tags that are taged to only pages that have a specific parent?

I would like to use Using the WP_Query or Query_Posts.

I'm currently using the query_post method.

$terms_array = array();
if ($strurl == "somesite.com"){
$resparent = "18219"; //Page ID
$nocat = "-2,-4,-5,-6,-1014,-875,-25,-301"; //
}

query_posts('post_type=page&posts_per_page=500&taxonomy=guidance&cat='.$nocat.'');
if ( have_posts() ) : while ( have_posts() ) : the_post();
        $terms = get_the_terms($post->ID, 'post_tag');

        foreach ( $terms as $term ) {
          if (strlen($term->slug) >1){
          $terms_array[] = $term->slug.",".$term->name ;
}
        }
    endwhile; 
    wp_reset_postdata();
    wp_reset_query();
    endif;

This method does not seem to work.

So basically i would like my Tags not to be displayed if the tagged pages have a specific parent.