| @@ -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 | |
| @@ -134,12 +135,20 @@ | ||
| 134 | 135 | } |
| 135 | 136 | } |
| 136 | 137 | } |
| 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 = []; | |
| 144 | + } | |
| 145 | + | |
| 138 | 146 | $args = [ |
| 139 | 147 | 'post_type' => $post_type, |
| 140 | 148 | 'posts_per_page' => 5, |
| 141 | 149 | 'post__not_in' => [$post_id], |
| 150 | + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- admin-only endpoint listing pillar posts; there is no taxonomy to key this on. | |
| 142 | 151 | 'meta_query' => [ |
| 143 | 152 | [ |
| 144 | 153 | 'key' => '_thinkrank_pillar_content', |
| 145 | 154 | 'value' => '1', |
| @@ -145,8 +154,9 @@ | ||
| 145 | 154 | 'value' => '1', |
| 146 | 155 | 'compare' => '=', |
| 147 | 156 | ] |
| 148 | 157 | ], |
| 158 | + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- admin-only endpoint, optional filter. | |
| 149 | 159 | 'tax_query' => $tax_query, |
| 150 | 160 | 'fields' => 'ids' |
| 151 | 161 | ]; |
| 152 | 162 | |