Make WordPress Core

Ticket #4304: category_exclusion_fix.patch

File category_exclusion_fix.patch, 1.8 KB (added by stewartjohnson, 19 years ago)

SVN patch to fix the bug, and add some missing error checking on intval()

  • link-template.php

     
    286286                $join .= ')';
    287287        }
    288288
    289         $sql_exclude_cats = '';
     289        $posts_in_ex_cats_sql = '';
    290290        if ( !empty($excluded_categories) ) {
    291                 $blah = explode(' and ', $excluded_categories);
    292                 foreach ( $blah as $category ) {
     291                $excluded_category_list = explode(' and ', $excluded_categories);
     292        $sql_cat_ids = '';
     293                foreach ( $excluded_category_list as $category ) {
    293294                        $category = intval($category);
    294                         $sql_cat_ids = " OR pc.category_ID = '$category'";
     295            if ($category > 0) {
     296                $sql_cat_ids .= " OR pc.category_ID = '$category'";
     297            }
    295298                }
    296299                $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id=p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID");
    297300                $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';
     
    323326                $join .= ')';
    324327        }
    325328
    326         $sql_exclude_cats = '';
     329        $posts_in_ex_cats_sql = '';
    327330        if ( !empty($excluded_categories) ) {
    328                 $blah = explode(' and ', $excluded_categories);
    329                 foreach ( $blah as $category ) {
     331                $excluded_category_list = explode(' and ', $excluded_categories);
     332        $sql_cat_ids = '';
     333                foreach ( $excluded_category_list as $category ) {
    330334                        $category = intval($category);
    331                         $sql_cat_ids = " OR pc.category_ID = '$category'";
     335            if ($category > 0) {
     336                $sql_cat_ids .= " OR pc.category_ID = '$category'";
     337            }
    332338                }
    333339                $posts_in_ex_cats = $wpdb->get_col("SELECT p.ID from $wpdb->posts p LEFT JOIN $wpdb->post2cat pc ON pc.post_id = p.ID WHERE 1 = 0 $sql_cat_ids GROUP BY p.ID");
    334340                $posts_in_ex_cats_sql = 'AND ID NOT IN (' . implode($posts_in_ex_cats, ',') . ')';