-
Notifications
You must be signed in to change notification settings - Fork 1
/
class-post-meta.php
43 lines (37 loc) · 1.18 KB
/
class-post-meta.php
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
<?php
/**
* Elasticsearch Extensions: Post_Meta Aggregation Class
*
* @package Elasticsearch_Extensions
*/
namespace Elasticsearch_Extensions\Aggregations;
use Elasticsearch_Extensions\DSL;
/**
* Post_Meta aggregation class. Responsible for building the DSL and requests
* for aggregations as well as holding the result of the aggregation after a
* response was received.
*/
class Post_Meta extends Term {
/**
* The postmeta key this aggregation is associated with.
*
* @var string
*/
protected string $meta_key;
/**
* Configure the Post_Meta aggregation.
*
* @param DSL $dsl The DSL object, initialized with the map from the adapter.
* @param array $args Optional. Additional arguments to pass to the aggregation.
*/
public function __construct( DSL $dsl, array $args ) {
if ( ! empty( $args['meta_key'] ) ) {
$this->label = ucwords( str_replace( [ '-', '_' ], ' ', $args['meta_key'] ) );
$this->meta_key = $args['meta_key'];
$this->query_var = 'post_meta_' . $args['meta_key'];
$this->term_field = $dsl->map_meta_field( $args['meta_key'], $args['data_type'] ?? '' );
unset( $args['meta_key'] );
}
parent::__construct( $dsl, $args );
}
}