title: Wordpress: Use Custom Field Value as Tag in Wp_Query
body: <p>I'm trying a Wp_Query that will take the content of a given custom field of the current post, identify the one tag that is the exact same word(s) as the content of the custom field, and then give me a list of other posts that also have that tag. For example: Custom_Field content is "Paris". Paris is also a tag for the same post (and others). I want the query to make this link and then list more posts that have the tag "Paris". Since some of the tags have multiple words I'd prefer to stay away from slugs and use IDs instead.</p>
  
  <p><code>$field = get_post_meta($post-&gt;ID, 'Custom_Field', true);
  $term = term_exists( $field, 'post_tag' );
  $term = $term[0]-&gt;tag_ID;</code></p>
  
  <p>Using the above (not saying it's the right/best way to do it), I've been able to identify the tag and get its ID, but I can't seem to be able to use it within the arguments of the query. </p>
  
  <pre><code>'tag_id' =&gt; $term
  </code></pre>
  
  <p>not working. I've tested this on multiple posts which all have different content for the given custom field and every time the tag ID that matches that content of the custom field has been returned correctly. So, the part that makes the link between the custom field and the tag works. I just can't get the ID of that tag to work with the arguments of the query.</p>
  
  <p>Either an actual solution or a link to another post that solves the problem would be highly appreciated (I haven't been able to find one).</p>
  
  <p>EDIT: WP_Query Code:</p>
  
  <pre><code>&lt;?php
  
  global $post;
  $field = get_post_meta($post-&gt;ID, 'Custom_Field', true);
  $term = term_exists( $field, 'post_tag' );
  $term = $term[0]-&gt;tag_ID; 
  
  $args = array(
      'tax_query' =&gt; array(
            array(    
              'taxonomy' =&gt; 'post_tag',
              'field' =&gt; 'tag_ID',
              'terms' =&gt; $term
            )
         ),
      'posts_per_page' =&gt; '5',
      'orderby' =&gt; 'rand',
      'post__not_in' =&gt; array(get_the_ID())
      );
  
  $query = new WP_Query( $args );
  
      while ( $query-&gt;have_posts() ) : $query-&gt;the_post(); ?&gt;
  
               &lt;h4&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title (); ?&gt;&lt;/a&gt;&lt;/h4&gt;
  
     &lt;?php wp_reset_postdata(); ?&gt;
  </code></pre>