Location.php
1.41 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
48
49
50
51
<?php
namespace ACA\ACF\Search\Comparison\FieldGroup;
use AC\Helper\Select\Options;
use ACP\Search\Comparison;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
class Location extends Comparison implements Comparison\Values {
public function __construct() {
$operators = new Operators( [
Operators::EQ,
] );
parent::__construct( $operators );
}
protected function create_query_bindings( $operator, Value $value ) {
global $wpdb;
$binding = new Bindings();
$groups = acf_get_field_groups( [ $value->get_value() => true ] );
$ids = is_array( $groups ) ? wp_list_pluck( $groups, 'ID' ) : [];
if ( empty( $ids ) ) {
$ids = [ 0 ];
}
$binding->where( sprintf( $wpdb->posts . '.ID IN (%s)', implode( ',', $ids ) ) );
return $binding;
}
public function get_values() {
return Options::create_from_array( [
'block' => _x( 'Block', 'ACF location', 'codepress-admin-columns' ),
'user_form' => _x( 'Users', 'ACF location', 'codepress-admin-columns' ),
'taxonomy' => __( 'Taxonomy' ),
'comment' => __( 'Comment' ),
'post_type' => _x( 'Post Type', 'ACF location', 'codepress-admin-columns' ),
'widget' => _x( 'Widget', 'ACF location', 'codepress-admin-columns' ),
'options_page' => _x( 'Option Page', 'ACF location', 'codepress-admin-columns' ),
'nav_menu' => _x( 'Menu', 'ACF location', 'codepress-admin-columns' ),
] );
}
}