CustomFields.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Helper\Select\Entities; |
| 4 | |
| 5 | use AC; |
| 6 | use AC\Helper\Select; |
| 7 | use AC\Helper\Select\Value; |
| 8 | |
| 9 | class CustomFields extends Select\Entities |
| 10 | implements Select\Paginated { |
| 11 | |
| 12 | /** |
| 13 | * @param array $args |
| 14 | * @param Value $value |
| 15 | */ |
| 16 | public function __construct( array $args = [], Value $value = null ) { |
| 17 | if ( null === $value ) { |
| 18 | $value = new Value\NullFormatter(); |
| 19 | } |
| 20 | |
| 21 | $args = array_merge( [ |
| 22 | 'meta_type' => 'post', |
| 23 | 'post_type' => false, |
| 24 | ], $args ); |
| 25 | |
| 26 | $query = new AC\Meta\Query( $args['meta_type'] ); |
| 27 | |
| 28 | $query->select( 'meta_key' ) |
| 29 | ->distinct() |
| 30 | ->order_by( 'meta_key' ); |
| 31 | |
| 32 | if ( $args['post_type'] ) { |
| 33 | $query->where_post_type( $args['post_type'] ); |
| 34 | } |
| 35 | |
| 36 | parent::__construct( $query->get(), $value ); |
| 37 | } |
| 38 | |
| 39 | public function get_total_pages() { |
| 40 | return 1; |
| 41 | } |
| 42 | |
| 43 | public function get_page() { |
| 44 | return 1; |
| 45 | } |
| 46 | |
| 47 | public function is_last_page() { |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | } |