Skip to content

Commit

Permalink
Merge pull request #99 from 10up/feature/tax-query
Browse files Browse the repository at this point in the history
Add tax_query support.
  • Loading branch information
tlovett1 committed Sep 9, 2014
2 parents 65c6547 + 9946ff5 commit 3037c4b
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions classes/class-ep-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,49 @@ public function format_args( $args ) {
'post_content',
);

/**
* Tax Query support
*
* Support for the tax_query argument of WP_Query
* Currently only provides support for the 'AND' relation between taxonomies
*
* @use field = slug
* terms array
* @since 0.9.1
*/
if ( ! empty( $args['tax_query'] ) ) {
$tax_filter = array();

foreach( $args['tax_query'] as $single_tax_query ) {
if ( ! empty( $single_tax_query['terms'] ) && ! empty( $single_tax_query['field'] ) && 'slug' === $single_tax_query['field'] ) {
$terms = (array) $single_tax_query['terms'];
$tax_filter[]['terms'] = array(
'terms.' . $single_tax_query['taxonomy'] . '.slug' => $terms,
);
}
}

if ( ! empty( $tax_filter ) ) {
$filter['and'][]['bool']['must'] = $tax_filter;
}
}

/**
* Allow for searching by taxonomy
*
* @since 0.9.0
*/
if ( ! empty( $args['search_tax'] ) ) {
foreach ( $args['search_tax'] as $tax ) {
$search_fields[] = 'terms.' . $tax . '.name';
}
}

/**
* Allow for searching by meta
*
* @since 0.9.0
*/
if ( ! empty( $args['search_meta'] ) ) {
foreach ( $args['search_meta'] as $key ) {
$search_fields[] = 'post_meta.' . $key;
Expand Down

0 comments on commit 3037c4b

Please sign in to comment.