-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtaxonomy.php
More file actions
33 lines (29 loc) · 820 Bytes
/
taxonomy.php
File metadata and controls
33 lines (29 loc) · 820 Bytes
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
<?php
/**
* Taxonomy relation functions
*
* @package AdvancedQueryLoop\Taxonomy
*/
namespace AdvancedQueryLoop\Taxonomy;
// Prevent direct access.
defined( 'ABSPATH' ) || exit;
function convert_names_to_ids( $names, $tax ) {
$rtn = [];
foreach ( $names as $name ) {
$term = get_term_by( 'name', $name, $tax );
if ( $term ) {
$rtn[] = $term->term_id;
}
}
return $rtn;
}
function parse_taxonomy_query( $tax_query_data ) {
return [
[
'taxonomy' => $tax_query_data['taxonomy'],
'terms' => convert_names_to_ids( $tax_query_data['terms'], $tax_query_data['taxonomy'] ),
'include_children' => ( ! isset( $tax_query_data['include_children'] ) || 'true' === $tax_query_data['include_children'] ) ? true : false,
'operator' => $tax_query_data['operator'],
],
];
}