Taxonomy TermsFREE

Docs Fields Taxonomy Terms

#Field Render

Display a Taxonomy Terms selector as radio, checkbox or select field type.

Field Group

#Field Settings

Setting nameDescription
Allow TaxonomiesFilter which taxonomy can be chosen
Allow TermsFilter which terms of the allowed taxonomies can be chosen
AppearanceSelect the appearance of this field: checkbox, radio or select
Return ValueReturn the terms name, object or ID
Save TermsConnect selected terms to the post
Load TermsLoad value from posts terms
Radio: LayoutChoose the layout: vertical or horizontal
Checkbox: LayoutChoose the layout: vertical or horizontal
Checkbox: ToggleAllow to toggle all values
Select: Allow NullAllow empty value
Select: Select multiple valuesAllow multiple values selection
Select: Stylised UIEnable Select2 UI style
Select: Placeholder TextAppears within the input
Select: Ajax lazy loadUse AJAX to lazy load choices

#Field Value

#Return Format: Term Object

$taxonomy_terms = get_field('taxonomy_terms');

/**
 * array(
 *     'term_id'          => 24,
 *     'name'             => 'Term 1',
 *     'slug'             => 'term-1',
 *     'term_group'       => 0,
 *     'term_taxonomy_id' => 24,
 *     'taxonomy'         => 'my-taxonomy',
 *     'description'      => '',
 *     'parent'           => 0,
 *     'count'            => 2,
 *     'filter'           => 'raw',
 * )
 */

#Return Format: Term Name

$taxonomy_terms = get_field('taxonomy_terms');

// Term 1

#Return Format: Term ID

$taxonomy_terms = get_field('taxonomy_terms');

// 24

#Unformatted Value

$taxonomy_terms = get_field('taxonomy_terms', false, false);

// 24

#Custom Query

/**
 * acfe/fields/taxonomy_terms/query
 * 
 * @array        $args     Query arguments
 * @array        $field    Field settings
 * @bool/string  $post_id  Current Post ID
 */
filter('acfe/fields/taxonomy_terms/query',                         $args, $field, $post_id);
filter('acfe/fields/taxonomy_terms/query/name=my_taxonomy_terms',  $args, $field, $post_id);
filter('acfe/fields/taxonomy_terms/query/key=field_5ff50f25a59f6', $args, $field, $post_id);
add_filter('acfe/fields/taxonomy_terms/query/name=my_taxonomy_terms', 'my_acf_taxonomy_terms_query', 10, 3);
function my_acf_taxonomy_terms_query($args, $field, $post_id){
    
    // change orderby
    // see: https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
    $args['orderby'] = 'count';
    
    // return
    return $args;

}

#Custom Result

/**
 * acfe/fields/taxonomy_terms/result
 * 
 * @string       $text     Term name result
 * @array        $term     Term object
 * @array        $field    Field settings
 * @bool/string  $post_id  Current Post ID
 */
filter('acfe/fields/taxonomy_terms/result',                         $text, $term, $field, $post_id);
filter('acfe/fields/taxonomy_terms/result/name=my_taxonomy_terms',  $text, $term, $field, $post_id);
filter('acfe/fields/taxonomy_terms/result/key=field_5ff50f25a59f6', $text, $term, $field, $post_id);
add_filter('acfe/fields/taxonomy_terms/result/name=my_taxonomy_terms', 'my_acf_taxonomy_terms_result', 10, 4);
function my_acf_taxonomy_terms_result($text, $term, $field, $post_id){
    
    // change term name result
    $text = "<strong>{$text}</strong>";
    
    // return
    return $text;

}