| @@ -114,8 +114,9 @@ | ||
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | $taxonomies = get_object_taxonomies($post_type); |
| 117 | 117 | $tax_query = []; |
| 118 | + $has_terms = false; | |
| 118 | 119 | |
| 119 | 120 | if (!empty($taxonomies)) { |
| 120 | 121 | $tax_query['relation'] = 'OR'; |
| 121 | 122 | |
| @@ -132,8 +133,15 @@ | ||
| 132 | 133 | $has_terms = true; |
| 133 | 134 | } |
| 134 | 135 | } |
| 135 | 136 | } |
| 137 | + } | |
| 138 | + | |
| 139 | + // Without this the query kept a tax_query holding nothing but | |
| 140 | + // 'relation' => 'OR' whenever the post had no terms — $has_terms was | |
| 141 | + // assigned and never read. | |
| 142 | + if (!$has_terms) { | |
| 143 | + $tax_query = []; | |
| 136 | 144 | } |
| 137 | 145 | |
| 138 | 146 | $args = [ |
| 139 | 147 | 'post_type' => $post_type, |