Taxonomy.php
939 Bytes
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 ACA\MetaBox\Search\Comparison;
use ACP;
class Taxonomy extends ACP\Search\Comparison\Post\Taxonomy {
/**
*
*/
private function get_term_by_id( $term_id ) {
global $wpdb;
$_tax = $wpdb->get_row( $wpdb->prepare( "
SELECT t.*
FROM $wpdb->term_taxonomy AS t
WHERE t.term_id = %s
LIMIT 1"
, $term_id ) );
if ( ! $_tax || is_wp_error( $_tax ) ) {
return false;
}
return get_term( $term_id, $_tax->taxonomy );
}
protected function create_query_bindings( $operator, ACP\Search\Value $value ) {
$bindings = new ACP\Search\Query\Bindings\Post();
$term = $this->get_term_by_id( $value->get_value() );
if ( $term ) {
$tax_query = ACP\Search\Helper\TaxQuery\ComparisonFactory::create(
$term->taxonomy,
$operator,
$value
);
$bindings = new ACP\Search\Query\Bindings\Post();
$bindings->tax_query( $tax_query->get_expression() );
}
return $bindings;
}
}