Support

Account

Home Forums ACF PRO acf/fields/taxonomy/query doesn't return the same result which get_terms() does Reply To: acf/fields/taxonomy/query doesn't return the same result which get_terms() does

  • Hi @hiroshi

    I’m afraid this is not possible because ACF will try to get the parents if the taxonomy is hierarchical so that it can show the terms in a tree layout. To fix it, you need to modify the core file. In “wp-content/plugins/advanced-custom-fields-pro/fields/taxonomy.php”, please search this line of code:

    // this will fail if a search has taken place because parents wont exist
    if( empty($args['search']) ) {

    Kindly change it to this one:

    // this will fail if a search has taken place because parents wont exist
    if( empty($args['search']) && $parent ) {

    After that, you can use this code to show only the child:

    function myfunction( $args, $field, $post_id ) {
    
    	$parents_args = array(
    		'hide_empty' => 0,
    		'parent' => 0,
    		'fields' => 'ids',
    		);
    	$parent_ids = get_terms( 'custom-taxonomy', $parents_args );
    	
    	$args['exclude'] = $parent_ids;
    
        return $args;
    
    }
    add_filter('acf/fields/taxonomy/query/name=taxonomy', 'myfunction', 10, 3);

    Also, could you please open a new ticket so this issue can be passed directly to the plugin author? You can open a new ticket here: https://support.advancedcustomfields.com/new-ticket.

    Thanks 🙂