Title: ldwriters's Replies | WordPress.org

---

# ldwriters

  [  ](https://wordpress.org/support/users/ldwriters/)

 *   [Profile](https://wordpress.org/support/users/ldwriters/)
 *   [Topics Started](https://wordpress.org/support/users/ldwriters/topics/)
 *   [Replies Created](https://wordpress.org/support/users/ldwriters/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/ldwriters/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/ldwriters/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/ldwriters/engagements/)
 *   [Favorites](https://wordpress.org/support/users/ldwriters/favorites/)

 Search replies:

## Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [How to pass a variable into my tax_query terms parameter?](https://wordpress.org/support/topic/how-to-pass-a-variable-into-my-tax_query-terms-parameter/)
 *  Thread Starter [ldwriters](https://wordpress.org/support/users/ldwriters/)
 * (@ldwriters)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/how-to-pass-a-variable-into-my-tax_query-terms-parameter/#post-3037182)
 * This is what I ended up doing and it works.
 * `’tax_query’ => array(
    array( ‘taxonomy’ => ‘b’, ‘field’ => ‘slug’, ‘terms’ 
   => wp_get_post_terms($post->ID, ‘b’, array(“fields” => “names”))
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [How to pass a variable into my tax_query terms parameter?](https://wordpress.org/support/topic/how-to-pass-a-variable-into-my-tax_query-terms-parameter/)
 *  Thread Starter [ldwriters](https://wordpress.org/support/users/ldwriters/)
 * (@ldwriters)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/how-to-pass-a-variable-into-my-tax_query-terms-parameter/#post-3036974)
 * I need the terms in my tax_query to be the ones from the current post. In order
   to do this I am using a variable. The value of the variable is given by using
   the get_terms() function.
 * The problem is that it is not returning anything. It does however return the 
   correct posts when I manually put the terms in the array.
 * How do I grab the posts terms automatically and place them in the terms parameter?
 * Here is the code that I am using.
 *     ```
       <?php
       //for use in the loop, list 5 post titles related to first tag on current post
       $tags1 = get_terms($post->ID, 'b');
       if ($tags1) {
       echo '<div id="productsideheaders"><h2>PRODUCTS</h2></div>';
       $args = array(
       	'tax_query' => array(
       		array(
       			'taxonomy' => 'b',
       			'terms' => array('$tags1'),
       			'field' => 'slug',
   
       		)
       	)
       );
       $query = new WP_Query( $args );
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
       while ($my_query->have_posts()) : $my_query->the_post(); ?>
       <div style="width: 270px;float: left;">
       <?php if ( has_post_thumbnail()) :  ?>
       <a>" title="<?php the_title_attribute(); ?>" >
       <?php the_post_thumbnail( array(40,40) ); ?>
       </a> <span style="font-size: 10pt;"><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title('' ); ?></a></span></div>
       <?php endif; ?>
        		<?php
       endwhile;
       }
       }
       ?>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)