ChildPages.php
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace ACP\Search\Comparison\Post;
use ACP\Search\Comparison;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
class ChildPages extends Comparison {
/** @var string */
private $post_type;
public function __construct( $post_type ) {
$operators = new Operators( [
Operators::IS_EMPTY,
Operators::NOT_IS_EMPTY,
] );
$this->post_type = $post_type;
parent::__construct( $operators );
}
protected function create_query_bindings( $operator, Value $value ) {
global $wpdb;
$operator = $operator === Operators::NOT_IS_EMPTY
? 'IN'
: 'NOT IN';
$where = $wpdb->prepare( "{$wpdb->posts}.ID {$operator} (
SELECT DISTINCT {$wpdb->posts}.post_parent
FROM {$wpdb->posts}
WHERE {$wpdb->posts}.post_parent > 1
AND {$wpdb->posts}.post_status = 'publish'
AND {$wpdb->posts}.post_type = %s
)", $this->post_type );
$bindings = new Bindings();
$bindings->where( $where );
return $bindings;
}
}