Exemplo n.º 1
0
 function get_terms($value, $taxonomy = 'category')
 {
     // load terms in 1 query to save multiple DB calls from following code
     if (count($value) > 1) {
         $terms = acf_get_terms(array('taxonomy' => $taxonomy, 'include' => $value, 'hide_empty' => false));
     }
     // update value to include $post
     foreach (array_keys($value) as $i) {
         $value[$i] = get_term($value[$i], $taxonomy);
     }
     // filter out null values
     $value = array_filter($value);
     // return
     return $value;
 }
Exemplo n.º 2
0
function acf_get_taxonomy_terms($taxonomies = array())
{
    // force array
    $taxonomies = acf_get_array($taxonomies);
    // get pretty taxonomy names
    $taxonomies = acf_get_pretty_taxonomies($taxonomies);
    // vars
    $r = array();
    // populate $r
    foreach (array_keys($taxonomies) as $taxonomy) {
        // vars
        $label = $taxonomies[$taxonomy];
        $is_hierarchical = is_taxonomy_hierarchical($taxonomy);
        $terms = acf_get_terms(array('taxonomy' => $taxonomy, 'hide_empty' => false));
        // bail early i no terms
        if (empty($terms)) {
            continue;
        }
        // sort into hierachial order!
        if ($is_hierarchical) {
            $terms = _get_term_children(0, $terms, $taxonomy);
        }
        // add placeholder
        $r[$label] = array();
        // add choices
        foreach ($terms as $term) {
            $k = "{$taxonomy}:{$term->slug}";
            $r[$label][$k] = acf_get_term_title($term);
        }
    }
    // return
    return $r;
}