How to decrease load time of join query in wordpress?

I am using $wpdb Object to display some data in WordPress post loop.

while ( have_posts() ) : the_post();
    echo '<li>';
    echo '</li>';

The code I want to put in that loop is:

<h3><font color="#F60"><?php
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare( "SELECT * FROM `link` gl, `social` ls WHERE `sd`= 12 AND gl.lik = '$lisd' AND gl.lik_id = ls.lik_id ORDER BY date DESC LIMIT 1" )); 
if (!$result) {
    echo "0";
     foreach($result as $row)
        echo abbNumber($shares);

?>  </font> <font color="#666">SHARES</font></h3>

Is there any way to run that query in that loop using ajax or can I run that query after page load? I want to decrease the load time of that query?

Source: wpdb

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.