Skip to content

Commit af60b60

Browse files
authored
Merge pull request #49 from stellarwp/feat/sub-where-clauses
Add support for nested sub-WHERE clauses and update hook naming
2 parents 6255ec1 + 73893a4 commit af60b60

File tree

26 files changed

+1215
-45
lines changed

26 files changed

+1215
-45
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard.
44

5+
## [3.2.0] 2026-01-05
6+
7+
* Feature - Add support for nested sub-WHERE clauses in `paginate()` and `get_total_items()` methods. This allows building complex queries like `WHERE (col1 = 'a' OR col2 = 'b') AND col3 = 'c'`.
8+
* Feature - Add new `stellarwp_schema_custom_table_paginate_query` filter to allow modification of the paginate query before execution.
9+
* Feature - Add new `stellarwp_schema_custom_table_total_items_query` filter to allow modification of the total items count query before execution.
10+
* Tweak - Rename hooks from `tec_common_*` prefix to `stellarwp_schema_*` prefix for consistency with the StellarWP namespace.
11+
12+
### Breaking Changes
13+
14+
The following hooks have been renamed:
15+
- `tec_common_custom_table_query_pre_results``stellarwp_schema_custom_table_query_pre_results`
16+
- `tec_common_custom_table_query_post_results``stellarwp_schema_custom_table_query_post_results`
17+
- `tec_common_custom_table_query_results``stellarwp_schema_custom_table_query_results`
18+
- `tec_common_custom_table_query_where``stellarwp_schema_custom_table_query_where`
19+
20+
[3.2.0]: https://github.com/stellarwp/schema/releases/tag/3.2.0
21+
522
## [3.1.4] 2025-10-16
623

724
* Fix - Handle array values correctly in the `get_*` query methods.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"symfony/event-dispatcher-contracts": "^2.5.1",
3131
"symfony/string": "^5.4",
3232
"szepeviktor/phpstan-wordpress": "^1.1",
33-
"php-stubs/wp-cli-stubs": "^2.11"
33+
"php-stubs/wp-cli-stubs": "^2.11",
34+
"lucatume/codeception-snapshot-assertions": "^0.5.0"
3435
},
3536
"minimum-stability": "stable",
3637
"autoload": {

composer.lock

Lines changed: 95 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/query-methods.md

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ $args = [
271271
'orderby' => 'created_at', // Column to sort by.
272272
'order' => 'DESC', // ASC or DESC.
273273
'offset' => 0, // Starting offset.
274-
'query_operator' => 'AND', // AND or OR.
274+
'query_operator' => 'AND', // AND or OR for top-level conditions.
275275

276276
// Column filters.
277277
[
@@ -284,6 +284,21 @@ $args = [
284284
'value' => 1000,
285285
'operator' => '<',
286286
],
287+
288+
// Sub-WHERE clauses (v3.2.0+) - group conditions with their own operator.
289+
[
290+
'query_operator' => 'OR', // Operator for this group.
291+
[
292+
'column' => 'type',
293+
'value' => 'classic',
294+
'operator' => '=',
295+
],
296+
[
297+
'column' => 'type',
298+
'value' => 'premium',
299+
'operator' => '=',
300+
],
301+
],
287302
];
288303
```
289304

@@ -321,6 +336,33 @@ $results = Sandwiches::paginate(
321336
1
322337
);
323338

339+
// Sub-WHERE clauses (v3.2.0+).
340+
// Query: WHERE (type = 'classic' OR type = 'premium') AND price_cents < 1500
341+
$results = Sandwiches::paginate(
342+
[
343+
[
344+
'query_operator' => 'OR',
345+
[
346+
'column' => 'type',
347+
'value' => 'classic',
348+
'operator' => '=',
349+
],
350+
[
351+
'column' => 'type',
352+
'value' => 'premium',
353+
'operator' => '=',
354+
],
355+
],
356+
[
357+
'column' => 'price_cents',
358+
'value' => 1500,
359+
'operator' => '<',
360+
],
361+
],
362+
20,
363+
1
364+
);
365+
324366
// With JOIN.
325367
$results = Sandwiches::paginate(
326368
$args,
@@ -498,28 +540,46 @@ Query methods provide hooks for customization:
498540

499541
```php
500542
// Before query execution.
501-
add_action( 'tec_common_custom_table_query_pre_results', function( $args, $class ) {
543+
add_action( 'stellarwp_schema_custom_table_query_pre_results', function( $args, $class ) {
502544
// Modify args, log, etc.
503545
}, 10, 2 );
504546

505547
// After query execution.
506-
add_action( 'tec_common_custom_table_query_post_results', function( $results, $args, $class ) {
548+
add_action( 'stellarwp_schema_custom_table_query_post_results', function( $results, $args, $class ) {
507549
// Log, analyze, etc.
508550
}, 10, 3 );
509551

510552
// Filter results.
511-
add_filter( 'tec_common_custom_table_query_results', function( $results, $args, $class ) {
553+
add_filter( 'stellarwp_schema_custom_table_query_results', function( $results, $args, $class ) {
512554
// Modify results.
513555
return $results;
514556
}, 10, 3 );
515557

516558
// Filter WHERE clause.
517-
add_filter( 'tec_common_custom_table_query_where', function( $where, $args, $class ) {
559+
add_filter( 'stellarwp_schema_custom_table_query_where', function( $where, $args, $class ) {
518560
// Add custom WHERE conditions.
519561
return $where;
520562
}, 10, 3 );
563+
564+
// Filter the paginate query before execution (v3.2.0+).
565+
add_filter( 'stellarwp_schema_custom_table_paginate_query', function( $query ) {
566+
// Modify the SQL query string before execution.
567+
// Useful for debugging, logging, or query modifications.
568+
error_log( "Paginate query: {$query}" );
569+
return $query;
570+
} );
571+
572+
// Filter the total items count query before execution (v3.2.0+).
573+
add_filter( 'stellarwp_schema_custom_table_total_items_query', function( $query ) {
574+
// Modify the SQL count query string before execution.
575+
// Useful for debugging, logging, or query modifications.
576+
error_log( "Total items query: {$query}" );
577+
return $query;
578+
} );
521579
```
522580

581+
> **Note (v3.2.0):** The hook names were changed from `tec_common_*` prefix to `stellarwp_schema_*` prefix. If you're upgrading from an earlier version, update your hook callbacks accordingly.
582+
523583
## Performance Tips
524584

525585
1. **Batch Operations**: Use `insert_many()` and `update_many()` for bulk operations
@@ -533,4 +593,4 @@ add_filter( 'tec_common_custom_table_query_where', function( $where, $args, $cla
533593
- [Column System](columns.md)
534594
- [Index System](indexes.md)
535595
- [Table Schemas](schemas-table.md)
536-
- [Migrating from v2 to v3](migrating-from-v2-to-v3.md)
596+
- [Migrating from v2 to v3](migrating-from-v2-to-v3.md)

0 commit comments

Comments
 (0)