
What you’re doing will only set the terms when the post is saved and you won’t see it until the next time the edit page is loaded. These things happen after the post is saved.
In order to preset a taxonomy field with a term you need to use an acf/prepare_field filter https://www.advancedcustomfields.com/resources/acf-prepare_field/ and set $field['default_value'] to the term you want, or an array of terms if the field allows multiple selections.

The name of the taxonomy for tags is actually “post_tag” so getting the field could look something like this
$image = get_field('tag_img', 'post_tag_'.$tag->term_id);
however, a lot has changed in 2 years. You could also use
$image = get_field('tag_img', 'term_'.$tag->term_id);
or even
$image = get_field('tag_img', $tag);

You have to show us your changed code if you want help, we aren’t psychic. But anyway, here is the modified code from your first example, assuming your field is now a taxonomy field with return value “Term Object”:
<div class="audio-tags">
<?php
$tags = get_field("etiquetas");
foreach($tags as $tag){
?>
<a href="<?php echo(esc_url(get_term_link($tag))); ?>"><?php echo($tag->name); ?></a>
<?php
}
?>
</div>
And the adjusted CSS for this would be:
.audio-tags {overflow: hidden;}
.audio-tags a {
position: relative;
display: inline-block;
margin-right: .5em;
}
.audio-tags a:before {
content: '';
width: .25em;
height: .25em;
position: absolute;
background-color: blue;
border-radius: 100%;
left: -.5em;
top: 50%;
transform: translateY(-50%);
}
I have made a taxonomy with car type with two options
1-sale
2.-parts
I select a post from (add car) and select taxonomy (sale)
But when i made a Post Object field with post of (add car) to select post that has category selected (sale) its showing empty but when i remove the taxonomy select options and select the category has whole (car type ) it shows all the posts ???
how can i fix this
problem link : https://support.advancedcustomfields.com/forums/topic/post-object-with-taxonomy-selection-not-working-in-acf-frontend/
I have made a taxonomy with car type with two options
1-sale
2.-parts
I select a post from (add car) and select taxonomy (sale)
But when i made a Post Object field with post of (add car) to select post that has category selected (sale) its showing empty but when i remove the taxonomy select options and select the category has whole (car type ) it shows all the posts ???
how can i fix this

It would probably not be impossible to do this, but it would be very difficult and I don’t know how to accomplish it.
If you have custom taxonomies for each post type would be one thing, but on the other hand if you are using a single taxonomy for all post types then it would get even more complicated.
In the latter case, that is using a single taxonomy for all post types, it would probably be impossible to do this and allow for terms to be added in the future and to automatically populate the field based on those unknown future terms. The only way that I can think of to work around this problem would be that if the taxonomy is hierarchical and all of the terms for a specific post type are all children of a main term used for that post type.
If you do have custom taxonomies (or even if you done) then using a taxonomy field is difficult because you would need to intercept the AJAX call that ACF makes to get the list of terms modify the request and inject the selected post type into that request. Then you’d need to build a filter that modifies the get_terms() query that ACF runs https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-query/.
If I needed to do this I would not use a taxonomy field. I would use another select field and I would populate the values of the second select field dynamically based on the selection of the first field as in this example https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example.
Thank you for your swift reply!
It’s unfortunate that the taxonomy field is not modular in the way I expected it to be since it would’ve made sense for the fields to function in the way I expected. Eespecially since how the documentation was worded, there wasn’t any reason for me to believe it wouldn’t work.
Thank you! I’ll consider building an acf/save_post action after a think about the effort/reward levels. It might just be something I include in the documentation for the editors and if they wonder why something isn’t showing up, then they’ll email me lol

The behavior you’re seeing is what will happen. Taxonomy fields with save/load terms cannot really be used as sub fields of a repeater.
For save terms, as each row is updates wp_set_post_terms() is called. This has the effect of deleting any current terms and setting the new ones.
For load terms it will only load the terms set in the last field update.
This can be an issue and it is not covered in the documentation. Because of the way ACF works the taxonomy field cannot know what happened the last time the value was saved. This same behavior can be seen if you create 2 top level taxonomy fields that pull terms from the same taxonomy. Basically what this means is that any post can only have a single occurrence of a taxonomy field for any taxonomy if you want to use save/load terms.
If you want to have save/load terms in a repeater (or flex field) you need turn these settings off. You must build an acf/save_post action. In this action you need to loop over the repeater, get all of the terms from all rows and then call wp_set_post_terms() yourself including the entire list of terms to be set.
But I want only one term to be introduced.
How do I introduce one term from the taxonomy?
It seems to me that the code I wrote is not good because it does not have an array.
Can you give me a piece of code that will filter and display only one term out of taxonomy?
I have post type called “brand” and taxonomy called “category_brand”. Under the “brand” post type I have a repeater field. That repeater field Includes two sub fields: number field called “grade”, and taxonomy field called “category” (the taxonomy display all the categories under “category_brand”)
it looks like this: the repeater field
In the taxonomy archive of “category_brand” I display only the “brands” of the current taxonomy.
The order of the posts need to be by the “grade” sub fields, (large to small number).
I’m troubling with getting the ‘meta_key’ from the grade field under the repeater. The thing is that I need to get the “grade” field only if it’s related to the current taxonomy – The “category” sub field in the repeater.
This is the code
$current_object=get_queried_object();
$current_object_tax= $current_object->taxonomy;
$current_object_tax_id= $current_object->term_id;
$post_args_current_tax = array(
'post_type' => 'brands',
'tax_query' => array(
array(
'taxonomy'=> $current_object_tax,
'field'=> 'term_id',
'terms' => $current_object_tax_id,
),
),
'posts_per_page' => -1,
'meta_key'=> 'categorygrade_0_grade',
'orderby'=> 'meta_value_num',
'order' => 'DESC',
);
$post_query_current_tax = new WP_Query($post_args_current_tax);
Right now this meta_key:’meta_key’=> ‘categorygrade_0_grade’, takes all the grades under the repeater and not only the grades that related to the current taxonomy. How can I get the grade only if it’s related to the current taxonomy in the repeater?

A taxonomy field probably the only field type that can be moved under the right conditions.
If the field has both “load terms” and “save terms” ticked on then you can move this field. The reason being that the values that ACF shows are actually the posts taxonomy/term relationship and not values stored in the post.
But if save terms and load terms are not turned on then you’ve got the same problem.
Thanks, glad I asked as there is no warning of this.
What is the best way to do this then? If a post is tagged to a taxonomy, and cannot move the field, if I set up a new taxonomy field in the other field group, could this populate some how so it is ticked in the categories it is associated with?
For Select or Multiselect dropdown use the below code to query only parents.
function hide_child_taxonomies( $args, $field ) {
if( 'YOUR_FIELD_NAME' === $field['_name'] ) {
$args['parent'] = 0;
}
return $args;
}
add_filter('acf/fields/taxonomy/query', 'hide_child_taxonomies', 10, 3);
For Select or Multiselect dropdown use the below code to query only parents.
function hide_child_taxonomies( $args, $field ) {
if( 'YOUR_FIELD_NAME' === $field['_name'] ) {
$args['parent'] = 0;
}
return $args;
}
add_filter('acf/fields/taxonomy/query', 'hide_child_taxonomies', 10, 3);

If you are talking about the WP search form, No, you cannot search posts by term name. The built in WP search will not even search posts by term even without ACF. https://wordpress.stackexchange.com/questions/2623/include-custom-taxonomy-term-in-search

The default order of terms in WP is alphabetically by term name and ACF does not apply any arguments to change this except to show hierarchical taxonomies group by parent term.
If you are seeing a different order I would look for a filter or some other cause of this issue.
The only filter in ACF that can be used to change this is acf/fields/taxonomy/query
It’s been a little while, but I wanted to build onto what ChrisAtMogul started here because this worked wonders for me, but I had to do some tweaking to get it to work the way I needed it.
Chris’s code is good for working with one multiselect field, because it allows you to whittle your results in the same field down. However, what I wanted to do was to select a parent taxonomy term in a select, and then have another ACF field directly after that only listed the child terms. That way, they could be pulled from ACF as distinct entities if need be.
So, this requires two fields, both assigned the Taxonomy type. And please note that this is only a singluar level parent/child relationship. Any further, and you’d need to add more to the JS and to the PHP to make this cascade into grandchildren, etc.
jQuery/Javascript
(function($){
$(document).ready( function() {
acf.add_filter('select2_ajax_data', function( data, args, $input, field, instance ){
var parent_field_key = 'field_5f4fcb8f3a1a2'; // Parent Field
var target_field_key = 'field_5f4fd4201446c'; // Child Field
if( data.field_key == target_field_key ){
var field_selector = 'select[name="acf[' + parent_field_key + ']"]'; //the select field holding the values already chosen
if( $(field_selector).val() != '' && $(field_selector).val() != null ){
parent_id = $(field_selector).val();
} else{
parent_id = 0; //nothing chosen yet, offer only top-level terms
}
data.parent = parent_id;
}
return data;
});
});
})(jQuery);
Functions file
function custom_acf_taxonomy_hierarchy( $args, $field, $post_id ){
$parent_id = false;
if ( $field['key'] == 'field_5f4fcb8f3a1a2' ) { // Parent
$parent_id = 0;
} else if ( $field['key'] == 'field_5f4fd4201446c' && !empty( $_POST['parent'] ) ) { // Child
$parent_id = (int)$_POST['parent'];
}
if ( $parent_id !== false ) {
$args['parent'] = $parent_id;
}
return $args;
}
add_filter('acf/fields/taxonomy/query/key=field_5f4fcb8f3a1a2', 'custom_acf_taxonomy_hierarchy',10,3); // Parent
add_filter('acf/fields/taxonomy/query/key=field_5f4fd4201446c', 'custom_acf_taxonomy_hierarchy',10,3); // Child
I hope this manages to help someone like ChrisAtMogul’s code helped me. Thanks again!

@tsinicakdex-cz getting a term does not get the ACF fields used on that term. https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
Thank you @hube2 and @kimclarke it works fine, but… I can’t see customes fileds I see only defaults:
Array
(
[0] => WP_Term Object
(
[term_id] => 655
[name] => Adalit
[slug] => adalit
[term_group] => 0
[term_taxonomy_id] => 655
[taxonomy] => katalog
[description] =>
[parent] => 0
[count] => 0
[filter] => raw
[term_order] => 0
)
)
P.S. my taxonomy haven’t got any posts (and it never get them), it’s only taxonomy with customes fields
Ok I ended up with a solution, here is the code, don’t hesitate to comment!
<?php $spes = get_field( 'rel_spes', false, false ); if ( $spes ) : ?>
<?php
$types = get_terms( array(
'taxonomy' => 'job-type',
'hide_empty' => true,
'object_ids' => $spes
)
);
foreach( $types as $type ) :
$args = array(
'post_type' => 'job',
'posts_per_page' => -1,
'post__in' => $spes,
'orderby' => 'post__in',
'tax_query' => array(
array(
'taxonomy' => 'job-type',
'terms' => $type->slug,
'field' => 'slug',
),
),
);
$jobs = new WP_Query($args);
?>
<p class="widget-title job-types"><?php echo $type->name; ?></p>
<ul class="sidebar-menu">
<?php foreach( $jobs->posts as $post ) : setup_postdata( $post ); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; wp_reset_postdata(); ?>
</ul>
<?php endforeach; ?>
<?php endif; ?>
I think I have solved it.
From what I understand for a taxonomy the value mst be the ID rather than the name or slug or whatever, so since I need to use the name I need to convert that to the ID. I found that I could do this using get_term_by();
This is the portion of code I needed to change:
// Get term by name 'windows' in custom taxonomy 'product-types'.
$termId = get_term_by( 'name', 'windows', 'product-types' );
// compose our query arguements
$args = array(
'post_type' => 'colourswatch',
'meta_query' => array(
array(
'key' => 'colour_swatch_$_availability', // repeater_$_subfield
'value' => $termId->term_id, // translate the term name into its ID
'compare' => 'LIKE'
)
)
);
@vipstephan This has been of help, thank you. With a little bit of experimentation I’ve been able to successfuly do a query based on a sub field that is a basic text field value but all attempts at doing the same for a custom taxonomy – which I was hoping to do – have so far failed.
In my updated code below the taxonomy is ‘availability’ and the taxonomy name I’m aiming to filter to in this case is ‘windows’.
In functions:
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'colour_swatch_$", "meta_key LIKE 'colour_swatch_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
and on my template:
<?php
$args = array(
'post_type' => 'colourswatch',
'meta_query' => array(
array(
'key' => 'colour_swatch_$_availability',
'value' => 'windows',
'compare' => 'LIKE'
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
?>
<div class="container container--narrow swatches">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="swatches__material">
<h3 class="swatches__title"><?php the_title(); ?></h3>
<?php if( have_rows( 'colour_swatch' ) ): ?>
<ul class="swatches__colours">
<?php while ( have_rows( 'colour_swatch' ) ) : the_row(); ?>
<li class="swatches__swatch">
<div class="swatches__colour" style="background:<?php the_sub_field( 'colour' ); ?>"></div>
<h4 class="swatches__name"><?php the_sub_field( 'colour_name' ); ?></h4>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
<?php endif; ?>
What am I missing?
What you want to do is very similar to this https://www.advancedcustomfields.com/resources/querying-relationship-fields 8 ball pool except that you’d be using querying “catalog” based on the taxonomy field and using the term ID value instead of the post ID value.
I did everything, thanks for help.
can’t find those settings mentioned here:
https://www.advancedcustomfields.com/blog/acf-pro-5-7-0-new-architecture-new-features/
does anyone got this to work native?
without multiple field groups. just conditional logic based on taxonomy field value?

What you want to do is very similar to this https://www.advancedcustomfields.com/resources/querying-relationship-fields/ except that you’d be using querying “catalog” based on the taxonomy field and using the term ID value instead of the post ID value.
$args = array(
'taxonomy' => 'catalog',
'meta_query' => array(
array(
'key' => 'producer'
'value' => '"'.$term_id.'"',
'compare' => 'LIKE'
)
)
);
get_terms($args);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.