close

WP从数据库查询帖子的写法

 global $wpdb;
        $list_query = $wpdb->get_results("SELECT ID,post_title FROM {$wpdb->posts} WHERE post_type = 'slb_list' AND post_status IN ('draft','publish')");
        if (!is_null($list_query)) {
          foreach($list_query as $list ) {
            ?>

等同于

$query = new WP_Query(array(
          'post_type'  => 'slb_list'
        ));
        while ($query->have_posts()) {
          $query->the_post();
Share :

下一篇: