Skip to content

Commit

Permalink
add taxonomy type field to posts query
Browse files Browse the repository at this point in the history
  • Loading branch information
lavolpecheprogramma authored Aug 31, 2020
1 parent 89aed9c commit 2665d4a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Aeria/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public function getPosts($parameters)
$parentID = (isset($parameters['parent_id'])) ? $parameters['parent_id'] : null;
$taxonomy = (isset($parameters['taxonomy'])) ? $parameters['taxonomy'] : null;
$taxonomyTerms = (isset($parameters['taxonomy_terms'])) ? $parameters['taxonomy_terms'] : null;
$taxonomyField = (isset($parameters['taxonomy_field'])) ? $parameters['taxonomy_field'] : 'term_id';
$orderBy = (isset($parameters['orderby'])) ? $parameters['orderby'] : null;
$order = (isset($parameters['order'])) ? $parameters['order'] : null;
$numberPosts = (isset($parameters['numberposts'])) ? $parameters['numberposts'] : -1;
Expand All @@ -231,16 +232,21 @@ public function getPosts($parameters)
's' => $searchField,
'post_type' => $postType,
'post_parent' => $parentID,
'tax_query' => [
[
'taxonomy' => $taxonomy,
'terms' => $taxonomyTerms
]
],
'orderby' => $orderBy,
'order' => $order,
'numberposts' => $numberPosts,
];

if (isset($taxonomy) || isset($taxonomyTerms)) {
$args['tax_query'] = [
[
'taxonomy' => $taxonomy,
'slug' => $taxonomyField,
'terms' => $taxonomyTerms,
],
];
}

$posts = get_posts($args);
$response = [];
foreach ($posts as $index => $post) {
Expand Down

0 comments on commit 2665d4a

Please sign in to comment.