Make WordPress Core

Ticket #29718: 29718.3.diff

File 29718.3.diff, 1.8 KB (added by nofearinc, 11 years ago)

where clause could be empty

  • wp-includes/taxonomy.php

     
    997997                );
    998998
    999999                $join = '';
     1000                $where = '';
    10001001
    10011002                $this->clean_query( $clause );
    10021003
     
    10401041
    10411042                } elseif ( 'NOT IN' == $operator ) {
    10421043
    1043                         if ( empty( $terms ) ) {
    1044                                 continue;
    1045                         }
     1044                        if ( ! empty( $terms ) ) {
     1045                            $terms = implode( ',', $terms );
     1046   
     1047                            $where = "$this->primary_table.$this->primary_id_column NOT IN (
     1048                                    SELECT object_id
     1049                                    FROM $wpdb->term_relationships
     1050                                    WHERE term_taxonomy_id IN ($terms)
     1051                            )";
     1052                        }
    10461053
    1047                         $terms = implode( ',', $terms );
    1048 
    1049                         $where = "$this->primary_table.$this->primary_id_column NOT IN (
    1050                                 SELECT object_id
    1051                                 FROM $wpdb->term_relationships
    1052                                 WHERE term_taxonomy_id IN ($terms)
    1053                         )";
    1054 
    10551054                } elseif ( 'AND' == $operator ) {
     1055                        if ( ! empty( $terms ) ) {
     1056                            $num_terms = count( $terms );
     1057   
     1058                            $terms = implode( ',', $terms );
     1059   
     1060                            $where = "(
     1061                                    SELECT COUNT(1)
     1062                                    FROM $wpdb->term_relationships
     1063                                    WHERE term_taxonomy_id IN ($terms)
     1064                                    AND object_id = $this->primary_table.$this->primary_id_column
     1065                            ) = $num_terms";
     1066                        }
    10561067
    1057                         if ( empty( $terms ) ) {
    1058                                 continue;
    1059                         }
    1060 
    1061                         $num_terms = count( $terms );
    1062 
    1063                         $terms = implode( ',', $terms );
    1064 
    1065                         $where = "(
    1066                                 SELECT COUNT(1)
    1067                                 FROM $wpdb->term_relationships
    1068                                 WHERE term_taxonomy_id IN ($terms)
    1069                                 AND object_id = $this->primary_table.$this->primary_id_column
    1070                         ) = $num_terms";
    1071 
    10721068                } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) {
    10731069
    10741070                        $where = $wpdb->prepare( "$operator (