title: Paginate Wordpress $wpdb Query?
body: <p>I have this query:</p>
  
  <pre><code>    &lt;?php
      $query= "SELECT wposts.* FROM $wpdb-&gt;posts wposts, $wpdb-&gt;postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'votes' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY CAST(wpostmeta.meta_value AS SIGNED) DESC LIMIT 10";
      $posts = $wpdb-&gt;get_results($query, OBJECT);
      if ($posts ) : foreach ($posts as $post):
      setup_postdata($post);
      ?&gt;
      // Post here 
      &lt;?php endforeach; endif; ?&gt;
      &lt;div class="pagination"&gt;
          &lt;?php wp_pagenavi(); ?&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>I'm using this because Wordpress can't properly order meta_values that uses numbers, anyway...everything works fine except I have no clue on how to paginate this using wp_pagenavi.</p>
  
  <p>Any idea?</p>