定制wpdb查询-如何按另一个表meta_count对POST进行排序

时间:2013-01-04 作者:Pushparaj Periyasamy

下面的自定义wpdb查询代码运行良好,但我需要排序依据

stt2_meta 桌子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);

    ?>
提前感谢

1 个回复
SO网友:Mridul Aggarwal
<?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);
?>
结束

相关推荐