acf/fields/taxonomy/query

Overview

This filter allows you to modify the $args array which is used to query the terms shown in the taxonomy field. The available arguments can be found in the get_terms() documentation.

Changelog

  • Added in v5.0.0

Parameters

Name Type Description
$args array An array of arguments passed to the get_terms() function
$field array An array containing all the field settings
$post_id mixed The ID for the current post being edited

Usage

There are 3 ways to hook into acf/fields/taxonomy/query filter.

  1. acf/fields/taxonomy/query – filter for every field
  2. acf/fields/taxonomy/query/name={$field_name} – filter for a specific field based on it’s name
  3. acf/fields/taxonomy/query/key={$field_key} – filter for a specific field based on it’s key

functions.php

<?php

function my_taxonomy_query( $args, $field, $post_id ) {
    
    // modify args
    $args['orderby'] = 'count';
    $args['order'] = 'ASC';
    
    
    // return
    return $args;
    
}

add_filter('acf/fields/taxonomy/query', 'my_taxonomy_query', 10, 3);

?>

Related

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.