| @@ -88,9 +88,9 @@ | ||
| 88 | 88 | * @param mixed $value |
| 89 | 89 | * |
| 90 | 90 | * @return $this |
| 91 | 91 | */ |
| 92 | - public function orWhere( $key, $value = null, $compare = '=' ) { | |
| 92 | + public function or_where( $key, $value = null, $compare = '=' ) { | |
| 93 | 93 | $this->meta_query_or[] = compact( 'key', 'value', 'compare' ); |
| 94 | 94 | |
| 95 | 95 | return $this; |
| 96 | 96 | } |
| @@ -102,9 +102,9 @@ | ||
| 102 | 102 | * @param array $values |
| 103 | 103 | * |
| 104 | 104 | * @return $this |
| 105 | 105 | */ |
| 106 | - public function whereIn( $key, array $values ) { | |
| 106 | + public function where_in( $key, array $values ) { | |
| 107 | 107 | $this->meta_query[] = array( |
| 108 | 108 | 'key' => $key, |
| 109 | 109 | 'value' => $values, |
| 110 | 110 | 'compare' => 'IN', |
| @@ -113,8 +113,21 @@ | ||
| 113 | 113 | return $this; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | + * Exclude posts by ID from query results | |
| 118 | + * | |
| 119 | + * @param int|array $ids Post ID or array of post IDs to exclude | |
| 120 | + * | |
| 121 | + * @return $this | |
| 122 | + */ | |
| 123 | + public function where_not_ids( $ids ) { | |
| 124 | + $this->args['post__not_in'] = (array) $ids; // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in -- Intentional exclusion, dataset is controlled and limited | |
| 125 | + | |
| 126 | + return $this; | |
| 127 | + } | |
| 128 | + | |
| 129 | + /** | |
| 117 | 130 | * Add a meta query condition for NULL value |
| 118 | 131 | * |
| 119 | 132 | * @param string $key |
| 120 | 133 | * |
| @@ -119,9 +132,9 @@ | ||
| 119 | 132 | * @param string $key |
| 120 | 133 | * |
| 121 | 134 | * @return $this |
| 122 | 135 | */ |
| 123 | - public function whereNull( $key ) { | |
| 136 | + public function where_null( $key ) { | |
| 124 | 137 | $this->meta_query[] = array( |
| 125 | 138 | 'key' => $key, |
| 126 | 139 | 'compare' => 'NOT EXISTS', |
| 127 | 140 | ); |
| @@ -150,25 +163,25 @@ | ||
| 150 | 163 | |
| 151 | 164 | /** |
| 152 | 165 | * Add a category query |
| 153 | 166 | * |
| 154 | - * @param string|int $slugOrId | |
| 167 | + * @param string|int $slug_or_id | |
| 155 | 168 | * |
| 156 | 169 | * @return $this |
| 157 | 170 | */ |
| 158 | - public function category( $slugOrId ) { | |
| 159 | - return $this->taxonomy( 'category', $slugOrId, is_numeric( $slugOrId ) ? 'term_id' : 'slug' ); | |
| 171 | + public function category( $slug_or_id ) { | |
| 172 | + return $this->taxonomy( 'category', $slug_or_id, is_numeric( $slug_or_id ) ? 'term_id' : 'slug' ); | |
| 160 | 173 | } |
| 161 | 174 | |
| 162 | 175 | /** |
| 163 | 176 | * Add a tag query |
| 164 | 177 | * |
| 165 | - * @param string|int $slugOrId | |
| 178 | + * @param string|int $slug_or_id | |
| 166 | 179 | * |
| 167 | 180 | * @return $this |
| 168 | 181 | */ |
| 169 | - public function tag( $slugOrId ) { | |
| 170 | - return $this->taxonomy( 'post_tag', $slugOrId, is_numeric( $slugOrId ) ? 'term_id' : 'slug' ); | |
| 182 | + public function tag( $slug_or_id ) { | |
| 183 | + return $this->taxonomy( 'post_tag', $slug_or_id, is_numeric( $slug_or_id ) ? 'term_id' : 'slug' ); | |
| 171 | 184 | } |
| 172 | 185 | |
| 173 | 186 | /** |
| 174 | 187 | * Set order by custom field |
| @@ -179,9 +192,9 @@ | ||
| 179 | 192 | * @return $this |
| 180 | 193 | */ |
| 181 | 194 | public function orderBy( $field, $direction = 'ASC' ) { |
| 182 | 195 | $this->args['orderby'] = 'meta_value'; |
| 183 | - $this->args['meta_key'] = $field; | |
| 196 | + $this->args['meta_key'] = $field; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Required for ordering by custom field | |
| 184 | 197 | $this->args['order'] = $direction; |
| 185 | 198 | |
| 186 | 199 | return $this; |
| 187 | 200 | } |
| @@ -194,12 +207,13 @@ | ||
| 194 | 207 | public function get() { |
| 195 | 208 | $this->args['numberposts'] = - 1; |
| 196 | 209 | |
| 197 | 210 | if ( $meta = $this->build_meta_query() ) { |
| 198 | - $this->args['meta_query'] = $meta; | |
| 211 | + $this->args['meta_query'] = $meta; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Meta query is necessary for filtering posts by custom fields | |
| 199 | 212 | } |
| 200 | 213 | |
| 201 | 214 | if ( $this->tax_query ) { |
| 215 | + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Required for filtering posts by taxonomy | |
| 202 | 216 | $this->args['tax_query'] = count( $this->tax_query ) > 1 |
| 203 | 217 | ? array_merge( array( 'relation' => 'AND' ), $this->tax_query ) |
| 204 | 218 | : $this->tax_query; |
| 205 | 219 | } |
| @@ -225,12 +239,13 @@ | ||
| 225 | 239 | $this->args['posts_per_page'] = $per_page; |
| 226 | 240 | $this->args['paged'] = $page; |
| 227 | 241 | |
| 228 | 242 | if ( $meta = $this->build_meta_query() ) { |
| 229 | - $this->args['meta_query'] = $meta; | |
| 243 | + $this->args['meta_query'] = $meta; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Meta query is necessary for filtering posts by custom fields | |
| 230 | 244 | } |
| 231 | 245 | |
| 232 | 246 | if ( $this->tax_query ) { |
| 247 | + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Required for filtering posts by taxonomy | |
| 233 | 248 | $this->args['tax_query'] = count( $this->tax_query ) > 1 |
| 234 | 249 | ? array_merge( array( 'relation' => 'AND' ), $this->tax_query ) |
| 235 | 250 | : $this->tax_query; |
| 236 | 251 | } |
| @@ -258,13 +273,13 @@ | ||
| 258 | 273 | public function first() { |
| 259 | 274 | $this->args['numberposts'] = 1; |
| 260 | 275 | |
| 261 | 276 | if ( $meta = $this->build_meta_query() ) { |
| 262 | - $this->args['meta_query'] = $meta; | |
| 277 | + $this->args['meta_query'] = $meta; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Meta query is necessary for filtering posts by custom fields | |
| 263 | 278 | } |
| 264 | 279 | |
| 265 | 280 | if ( $this->tax_query ) { |
| 266 | - $this->args['tax_query'] = $this->tax_query; | |
| 281 | + $this->args['tax_query'] = $this->tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Required for filtering posts by taxonomy | |
| 267 | 282 | } |
| 268 | 283 | |
| 269 | 284 | $posts = get_posts( $this->args ); |
| 270 | 285 | |
| @@ -280,13 +295,13 @@ | ||
| 280 | 295 | $this->args['posts_per_page'] = 1; |
| 281 | 296 | $this->args['fields'] = 'ids'; |
| 282 | 297 | |
| 283 | 298 | if ( $meta = $this->build_meta_query() ) { |
| 284 | - $this->args['meta_query'] = $meta; | |
| 299 | + $this->args['meta_query'] = $meta; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Meta query is necessary for filtering posts by custom fields | |
| 285 | 300 | } |
| 286 | 301 | |
| 287 | 302 | if ( $this->tax_query ) { |
| 288 | - $this->args['tax_query'] = $this->tax_query; | |
| 303 | + $this->args['tax_query'] = $this->tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Required for filtering posts by taxonomy | |
| 289 | 304 | } |
| 290 | 305 | |
| 291 | 306 | $query = new WP_Query( $this->args ); |
| 292 | 307 | |