Make WordPress Core

Ticket #4990: get_posts_cats.diff

File get_posts_cats.diff, 2.0 KB (added by filosofo, 18 years ago)
  • wp-includes/post.php

     
    195195
    196196        $defaults = array(
    197197                'numberposts' => 5, 'offset' => 0,
    198                 'category' => 0, 'orderby' => 'post_date',
     198                'category' => '', 'orderby' => 'post_date',
    199199                'order' => 'DESC', 'include' => '',
    200200                'exclude' => '', 'meta_key' => '',
    201201                'meta_value' =>'', 'post_type' => 'post',
     
    207207
    208208        $numberposts = (int) $numberposts;
    209209        $offset = (int) $offset;
    210         $category = (int) $category;
    211210        $post_parent = (int) $post_parent;
    212211
     212        foreach( (array) preg_split('/[,\s]+/', $category) as $cat ) {
     213                $cat = intval($cat);
     214                $cat = abs($cat);
     215                $cat_array[] = $cat;
     216        }
     217        $category = "'" . implode("', '", $cat_array) . "'";
     218
    213219        $inclusions = '';
    214220        if ( !empty($include) ) {
    215221                $offset = 0;    //ignore offset, category, exclude, meta_key, and meta_value, post_parent if using include
     
    254260        $query .= empty( $post_type ) ? '' : "AND post_type = '$post_type' ";
    255261        $query .= empty( $post_status ) ? '' : "AND post_status = '$post_status' ";
    256262        $query .= "$exclusions $inclusions " ;
    257         $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id = " . $category. ") ";
     263        $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id IN ($category) ) ";
    258264        $query .= empty( $post_parent ) ? '' : "AND $wpdb->posts.post_parent = '$post_parent' ";
    259265        $query .= empty( $meta_key ) | empty($meta_value)  ? '' : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )";
    260266        $query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;