title: Get a list of meta values and search for posts Wordpress
body: <p>how to link meta_values to make a search for posts  with the current meta?</p>
  
  <p>The code above, show in a dropdown all the meta_value of city meta_key and cpt post type </p>
  
  <pre><code>&lt;?php if ( have_posts() ) : ?&gt;
  //some code for title
  &lt;?php 
  $args = array(
      'post_type' =&gt; 'cpt',
      'post_status' =&gt; 'publish',
      'posts_per_page' =&gt; -1,
      'meta_key' =&gt; 'city',
      );
  $dbResult = new WP_Query($args);
  
      echo '&lt;ul class="menu dropdown-menu"&gt;';
              while ( $dbResult-&gt;have_posts() ) : $dbResult-&gt;the_post();
              $mykey_values = get_post_meta($id, 'city', false);
                  foreach ( $mykey_values as $key =&gt; $value ) { 
                  $by_link = esc_url(add_query_arg(array( 'b' =&gt; $value ))); ?&gt;
                  &lt;li&gt;&lt;a href="&lt;?php echo $by_link;?&gt;"&gt;  &lt;?php echo $value ?&gt;&lt;/a&gt;&lt;/li&gt;  
              &lt;?php   }
                  endwhile;   ?&gt;
          &lt;?php wp_reset_query(); ?&gt;
  
   &lt;?php
      echo '&lt;/ul&gt;'; ?&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>My problem is how to get a link of the values and search.</p>
  
  <p>So to get a link, I tried </p>
  
  <pre><code> $by_link = esc_url(add_query_arg(array( 'b' =&gt; $value ))); ?&gt;
  &lt;li&gt;&lt;a href="&lt;?php echo $by_link;?&gt;"&gt;  &lt;?php echo $value ?&gt;&lt;/a&gt;&lt;/li&gt;  
  </code></pre>
  
  <p>And to search I made another loop and tried to get b value:</p>
  
  <pre><code>&lt;?php 
  $meta_value = $_GET['b'] != '' ? $_GET['b'] :  '';
  $args2 = array(
      'post_type' =&gt; 'cpt',
      'post_status' =&gt; 'publish',
      'posts_per_page' =&gt; -1,
  
      'meta_query'    =&gt;  array(
                  array(
                  'key' =&gt; 'city',
                  'value'  =&gt;  $meta_value, 
                  'compare' =&gt; 'LIKE', 
              ),
      ),
  );
  $dbResult2 = new WP_Query($args2);
   while ( $dbResult2-&gt;have_posts() ) : $dbResult2-&gt;the_post(); ?&gt;
  
                  &lt;?php get_template_part( 'content', get_post_type() ); ?&gt;
  
              &lt;?php endwhile; ?&gt;
                      &lt;?php wp_reset_query(); ?&gt;
  </code></pre>
  
  <p>Any help???</p>