title: List posts with the same tag of current post in WordPress
body: <p>I have a site with 500 000 posts and it's pretty slow.</p>
  
  <p>In the bottom of every post on a WordPress site, I want to show only 3 random posts having the same tag of current post.</p>
  
  <p>Note that every post has always 1 tag only (no more, no less).</p>
  
  <p>I use the following code but the <code>SELECT</code> gets thousands of posts and it's extremely slow. </p>
  
  <p>Using <code>posts_per_page=3</code> it gets thousands of posts (with same tag) via query and after that, it shows 3 posts only but the MySQL load has been very high. Instead, the logic should be "find 3 posts only and then stop".</p>
  
  <pre><code>$posttags = get_the_tags();
  foreach($posttags as $tag) {
  $duot=$tag-&gt;slug; 
  $duot2=$tag-&gt;name; 
  }
  
  $the_query = new WP_Query( 'tag='.$duot.'&amp;posts_per_page=3' );
  if ( $the_query-&gt;have_posts() ) {
  echo '&lt;h3&gt;Other post with tag '.$duot2.'&lt;/h3&gt;&lt;ul&gt;';
  while ( $the_query-&gt;have_posts() ) {
  $the_query-&gt;the_post();
  echo '&lt;li &gt;'.the_title().'&lt;/li&gt;';
  }
  echo '&lt;/ul&gt;';
  } 
  
  wp_reset_postdata();
  </code></pre>
  
  <p>How would you change the above code to reduce the loading time of MySQL queries?</p>