title: WordPress Custom Select Query
body: <p>I really don't know enough about MySQL queries and it's showing.</p>
  
  <p>I have a custom field set for every post. The custom field stores the posts source URL in a key called "source_url".</p>
  
  <p>I have it working with the below WP_Query parameters, but <strong>it's incredibly slow</strong>. Keep in mind it's possible to 50+ urls to search for.</p>
  
  <p>So, given an array of source URL's, I want to fetch the matching posts. </p>
  
  <p>For example, here is what I currently have that's slow in WP_Query:</p>
  
  <pre><code>// var_dump of $urls array (this could be 50+ urls)
  array(7) {
    [0]=&gt;
    string(42) "http://www.youtube.com/watch?v=FMghvnqDhT8"
    [1]=&gt;
    string(42) "http://www.youtube.com/watch?v=RY-yUFpXTnM"
    [2]=&gt;
    string(58) "http://www.youtube.com/watch?v=nIm2dnyJ1Ps&amp;feature=related"
    [3]=&gt;
    string(42) "http://www.youtube.com/watch?v=NoCtRQlJAqM"
    [4]=&gt;
    string(57) "http://holidaycustoms.blogspot.com/2012/08/busy-week.html"
    [5]=&gt;
    string(42) "http://www.youtube.com/watch?v=DcZvg197Ie4"
    [6]=&gt;
    string(42) "http://www.youtube.com/watch?v=7P3UEbLmLuo"
  }
  
  // Build Media Query
  $meta_query = array(
      'relation' =&gt; 'OR'
  );
  foreach( $urls as $url ) {
      $meta_query[] = array(
                          'key'       =&gt; 'source_url',
                          'value'     =&gt; $url
                      );
  }
  
  // Get 20 matching posts from a category set by a variable
  $args = array(
      'post_type'        =&gt; 'post',
      'posts_per_page'   =&gt; 20,
      'orderby'          =&gt; 'rand',
      'cat'              =&gt; $cat_ID,
      'meta_query'       =&gt; $meta_query
  );
  $posts = get_posts($args);        
  </code></pre>
  
  <p>What I'm looking to do is replace the above code with a custom query select, <a href="http://wordpress-hackers.1065353.n5.nabble.com/Expensive-meta-query-Is-there-a-better-way-td38467.html" rel="nofollow">which I have read is much faster than WP_Query</a>.</p>
  
  <p><strong>But I don't know enough about MySQL or the WP database to build the custom select query. Can anyone help? Thanks in advance!</strong></p>