1

I would like to use Using the WP_Query or Query_Posts method.

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"; //Omitted Pages ID
}

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 taxonomy Tags to be displayed only if they are tagged to a page that has a specific parent.

  • Never ever use query_posts. It breaks the main query object, and many plugins and custom code relies on that – Pieter Goosen Jul 2 '15 at 16:18
0

From what I understand you have a loop that displays up to 500 pages. If the page parent = 18219 than you want to query the tags for that page. As far as I know, by default WP does not allow you to tag Pages, only Posts. But let's pretend you have a plugin that allows you to do that... Inside your loop you can check to see if the page has a parent equal to the ID you're looking for.

    //Check if this page has a parent equal to $resparent
    if($post->post_parent == $resparent){

      $terms = get_the_terms($post->ID, 'post_tag');

        foreach ( $terms as $term ) {
          if (strlen($term->slug) >1){
            $terms_array[] = $term->slug.",".$term->name ;
          }
        }
    }
| improve this answer | |

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.