WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

stt2_meta table meta_count


     $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
 $querystr = "SELECT {$wpdb->posts}.ID,
        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

Your Answer


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.