WordPress.org

Make WordPress Core

Ticket #4943: get_posts_category_list_and_exclusion.diff

File get_posts_category_list_and_exclusion.diff, 2.0 KB (added by johnjosephbachir, 11 years ago)
  • wp-includes/post.php

     
    178178        else
    179179                parse_str($args, $r);
    180180
    181         $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => 0,
     181        $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => '', 'category_exclude' = 0,
    182182                'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '',
    183183                'meta_key' => '', 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'publish', 'post_parent' => 0);
    184184        $r = array_merge($defaults, $r);
    185185        extract($r, EXTR_SKIP);
    186186        $numberposts = (int) $numberposts;
    187187        $offset = (int) $offset;
    188         $category = (int) $category;
     188        // $category = (int) $category; should remain textual
     189        $category_exclude = ( 1 == (int)$category_exclude ? 'NOT' : '');
    189190        $post_parent = (int) $post_parent;
    190191
    191192        $inclusions = '';
    192193        if ( !empty($include) ) {
    193194                $offset = 0;    //ignore offset, category, exclude, meta_key, and meta_value, post_parent if using include
    194                 $category = 0;
     195                $category = '';
    195196                $exclude = '';
    196197                $meta_key = '';
    197198                $meta_value = '';
     
    232233        $query .= empty( $post_type ) ? '' : "AND post_type = '$post_type' ";
    233234        $query .= empty( $post_status ) ? '' : "AND post_status = '$post_status' ";
    234235        $query .= "$exclusions $inclusions " ;
    235         $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") ";
     236        $query .= empty( $category ) ? '' : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id $category_exclude IN (" . $category. ")) ";
    236237        $query .= empty( $post_parent ) ? '' : "AND $wpdb->posts.post_parent = '$post_parent' ";
    237238        $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' )";
    238239        $query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;