Taxonomy.php
1.2 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
52
53
54
55
56
<?php
namespace ACP\Helper\Select\Entities;
use AC;
use ACP\Helper\Select\Value;
use WP_Term_Query;
class Taxonomy extends AC\Helper\Select\Entities
implements AC\Helper\Select\Paginated {
/**
* @var WP_Term_Query
*/
protected $query;
/**
* @param array $args
* @param AC\Helper\Select\Value $value
*/
public function __construct( array $args = [], AC\Helper\Select\Value $value = null ) {
if ( null === $value ) {
$value = new Value\Taxonomy();
}
$args = array_merge( [
'page' => 1,
'number' => 30,
'search' => '',
'hide_empty' => 0,
'taxonomy' => null,
], $args );
// calculate offset
$args['offset'] = ( $args['page'] - 1 ) * $args['number'];
$this->query = new WP_Term_Query( $args );
parent::__construct( $this->query->get_terms(), $value );
}
public function get_total_pages() {
$taxonomy = $this->query->query_vars['taxonomy'][0];
return absint( ceil( wp_count_terms( $taxonomy, $this->query->query_vars ) / $this->query->query_vars['number'] ) );
}
public function get_page() {
return $this->query->query_vars['page'];
}
public function is_last_page() {
return $this->get_total_pages() <= $this->get_page();
}
}