Advertisement
daymobrew

Tag query - AWP Facebook question

Sep 15th, 2016
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2.   $posttags = get_the_tags();
  3.  
  4.   foreach($posttags as $tag) {
  5.       if (is_numeric($tag->name)) {
  6.           $unit_number = $tag->slug;
  7.           echo '<p>History of tag ID: ', $unit_number, '</p>';
  8.           $unit_history_args = array('post_type' => 'post',
  9.                 'tax_query' => array(
  10.                     array( 'taxonomy' => 'post_tag',
  11.                             'field'    => 'slug',
  12.                             'terms'    => $unit_number,
  13.                             'operator' => 'EXISTS',
  14.                           ),
  15.                  ),
  16.                  );
  17.  
  18.           $the_query = new WP_Query( $unit_history_args );
  19.           if ( $the_query->have_posts() ) {
  20.               echo '<ul>';
  21.               while ( $the_query->have_posts() ) {
  22.                   $the_query->the_post();
  23.                   printf('<li><a href="%s">%s</a></li>', get_permalink(), get_the_title());
  24.               }
  25.               echo '</ul>';
  26.                      
  27.               /* Restore original Post Data */
  28.               wp_reset_postdata();
  29.           } else {
  30.               // no posts found
  31.           }
  32.       }
  33.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement