Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Custom wpdb query code below works well but I need sort by

stt2_meta table meta_count

,

 <?php
     $querystr = "
        SELECT ID, post_title FROM $wpdb->posts
                    WHERE post_type = 'post'
                        AND post_status = 'publish'
                        AND ID IN ( SELECT post_id FROM ".$wpdb->prefix."stt2_meta )
                    ORDER BY post_date DESC LIMIT 10;";
     $pageposts = $wpdb->get_results($querystr, OBJECT);

    ?>

Thanks in advance

share|improve this question
add comment

1 Answer

<?php
 $querystr = "SELECT {$wpdb->posts}.ID,
                     {$wpdb->posts}.post_title,
                     {$wpdb->prefix}stt2_meta.meta_count
        FROM {$wpdb->posts}, {$wpdb->prefix}stt2_meta
        WHERE {$wpdb->posts}.post_type = 'post'
          AND {$wpdb->posts}.post_status = 'publish'
          AND {$wpdb->posts}.ID IN ( SELECT post_id FROM {$wpdb->prefix}stt2_meta )
        ORDER BY {$wpdb->prefix}stt2_meta.meta_count DESC
        LIMIT 10;";
 $pageposts = $wpdb->get_results($querystr, OBJECT);
?>
share|improve this answer
    
Thanks, but It returns an empty page. No debug information available. –  Pushparaj Periyasamy Jan 5 '13 at 4:11
    
The query looks fine. I would start by running the generated query directly via phpmyadmin & checking the results or doing var_dump() on nearby code to get some other information –  Mridul Aggarwal Jan 5 '13 at 9:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.