WordPress.org

Make WordPress Core

Ticket #52: getposts-patch.diff

File getposts-patch.diff, 1.2 KB (added by iioshius, 9 years ago)
  • functions.php

    old new  
    16231623        parse_str($args, $r); 
    16241624        if (!isset($r['numberposts'])) $r['numberposts'] = 5; 
    16251625        if (!isset($r['offset'])) $r['offset'] = 0; 
    1626         // The following not implemented yet 
    16271626        if (!isset($r['category'])) $r['category'] = ''; 
     1627        // The following not implemented yet 
    16281628        if (!isset($r['orderby'])) $r['orderby'] = ''; 
    16291629        if (!isset($r['order'])) $r['order'] = ''; 
    16301630 
    16311631        $now = current_time('mysql'); 
    1632  
    1633         $posts = $wpdb->get_results("SELECT DISTINCT * FROM $wpdb->posts WHERE post_date <= '$now' AND (post_status = 'publish') GROUP BY $wpdb->posts.ID ORDER BY post_date DESC LIMIT " . $r['offset'] . ',' . $r['numberposts']); 
     1632         
     1633        $posts = $wpdb->get_results( 
     1634                "SELECT DISTINCT * " . 
     1635                "FROM $wpdb->posts " . 
     1636                ( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) . 
     1637                "WHERE post_date <= '$now' " . 
     1638                "AND (post_status = 'publish') ". 
     1639                ( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) . 
     1640                "GROUP BY $wpdb->posts.ID ". 
     1641                "ORDER BY post_date DESC ". 
     1642                "LIMIT " . $r['offset'] . ',' . $r['numberposts'] ); 
    16341643 
    16351644    update_post_caches($posts); 
    16361645