I am also having the same issue, and have followed the logic on the link above. However, all of the images I need already exist in the Artists custom post type, and I don’t want to have to upload a new image to go with each Product Taxonomy. Each artist has a bio image and a banner image in their record. I need to associate the artist’s banner image with an item in the online store. It’s working, but it’s relying on a plugin that is no longer supported, so I want to get it to work using the existing images.
Here is is the structure: I have a WooCommerce store with a taxonomy named product_artist. I have custom post types of Artists. Each artist has custom image fields: artist-bio & artist-banner. I need to display the artist-banner field on the WooCommerce template page. I have this code, but don’t know how to finish it, to display the image:
<?php
/** Begin add artist banner to top of product page **/
if(is_single()) {
$terms = get_the_terms( $post->ID, ‘product_artist’ );
if ( !empty( $terms ) ){
// get the first term
$term = array_shift( $terms );
}
$artist = $term->slug;
$short_url = get_site_url();
$url = $short_url . ‘/artists/’ . $artist;
$postid = url_to_postid( $url );
$posttype = get_post_type($postid);
}
?>
I don’t know what to do from here to get the banner image to show on the page. This works, but the plugin used is outdated and we want to move away from it.
<?php
// adds the banner image from Artist post associated with this single product displayed
if (class_exists(‘MultiPostThumbnails’)
&& MultiPostThumbnails::has_post_thumbnail($posttype, ‘banner-image’, $postid)) :?>
“>
<?php MultiPostThumbnails::the_post_thumbnail($posttype, ‘banner-image’, $postid);?>
<?php else : ?>
<?php endif; /** end artist banner **/?>
Thank you for any help you can give!

You need to supply the $post_id argument for have_rows(). This can either be a term object or it can be "term_{$term_id}"
In category.php you can use
$queried_object = get_queried_object();
and then
... have_rows('taxonomy_gallery_lightbox_image', $queried_object) ...

If I understand you want to include posts that are in 2 categories but exclude them if they are also in a third category.
I.E. Show if in category 76 but not if it is also in category 78.
I think that in order to do this you need to use a tax_query. I could be wrong but I do not think the ‘cat’ argument can be used the way you are trying to use it and I also thing that using ‘category__in’ combined with ‘category__not_in’ will work the same way. Like I said, I could be wrong but I think these arguments work as ‘OR’ (meaning category 76 OR not category 78).
$args['tax_query'] = array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'term_id'
'terms' => array(76, 77),
'operator' => 'IN'
),
array(
'taxonomy' => 'category',
'field' => 'term_id'
'terms' => array(78),
'operator' => 'NOT IN'
)
);
Thanak you, John, for your advice!
I think I will give the repeater field a try with the language being a dropdown selection of the language taxonomy terms. My only conern here is that the user can create duplicates of the same language, so maybe I need to find a JS-based solution to suppress this.
The hierarchical post type sounds interesting as well, I’ve never used this so far. But that would mean that you’d have to edit every language version separately, right? This could maybe get too time-consuming compared to having all the stuff in one place.
Thanks again,
Michael
Hi John,
Thanks for your extended feedback and your vision on the makes and models part. Basically this is already implemented as is as the case described above within a single taxonomy in a parent child construction.
I managed to change the text for the tooltip and title from the popup thanks to your valuable feedback. Much appreciated, thanks!
So i have only 1 thing to figure out and that is altering that parent selector field for the taxonomy.
I have been digging true the fields file at “acf/includes/fields/class-acf-field-taxonomy”.
So basically i need to be able to modify/extend the class “acf_field_taxonomy” / function “ajax_add_term” and change the behavior for field key X and Y.
I will have some sleep and see if i can come to somekind of solution 😀
if( is_taxonomy_hierarchical( $field['taxonomy'] ) ) {
$choices = array();
$response = $this->get_ajax_query($args);
if( $response ) {
foreach( $response['results'] as $v ) {
$choices[ $v['id'] ] = $v['text'];
}
}
acf_render_field_wrap(array(
'label' => __('Parent', 'acf'),
'name' => 'term_parent',
'type' => 'select',
'allow_null' => 1,
'ui' => 0,
'choices' => $choices
));
}
I was looking around to do this and found this resource, maybe at one time it was a location setting but now seems it isn’t? I’m hoping all the code to display things is still about right from the below page.
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
For now ive set the location as taxonomy and showing category gets it to display on all categories pages but i cant filter which categories it will display in, just defaults to all of them, which will do me for now.

As far as the popup goes, I can’t really help you. The modal foe adding a term is the modal built into WP. I have never found any information on how to change this.
You could, in a round-a-bout way, alter the tooltip.
That being said, if I needed to build something like this for a client I would not be using a single taxonomy for make and model. Please bare with me because this is only where I would start and the details of getting it done would need to be figured out.
First I would use two taxonomies, one for make and one for model. There would be a taxonomy field for the model term that allowed selecting the make term.
I would filter the values shown in the model field based on the selection made in the make field. This may actually require not using taxonomy fields, but I don’t know this for sure. I would need to look at the ACF JS API documentation to see if the AJAX request on this field could be altered to include the value selected in make. The exact details of this research would make the decision on how to proceed.
I would create my an acf/save_post action that would create the association between the model term and the make term when a new model term is added (basically look to see if the association already exists and if it does not then create it. Basically creating a parent/child association between these to taxonomies. Spitting the make and model taxonomies would also make it much easier to filter by these two fields and in the case of a model that is shared between 2 makes would mean that duplicate model entries would not be created.
Assuming that the client also wanted urls like /product/make/$make/model/$model/ I would also add custom rewrite rules to accomplish this.
Solved issue 1
add_filter('acf/fields/taxonomy/result/key=field_605b7c5cc9dc9', 'my_acf_fields_taxonomy_result2', 10, 4);
function my_acf_fields_taxonomy_result( $text, $term, $field, $post_id ) {
$text = $term->name;
return $text;
}
Feedback and issue 2 remains for the feature save/create terms.
2.1) How to turn of the parent selector on specific field.
2.2) Change the name of the tooltip/dialog(modal) with label name instead of the taxonomy.
2.3) In the dialog(modal) replacing the label of parent with custom label name of a field to field basis.
Ideally the should be some unique identification for the modals
UPDATE: For anyone else who encounters this…
It turns out, the first option DOES work. You can pass an array to a meta_value. HOWEVER, the operator ‘=’ does not work. Changing the compare to ‘IN’ works for my scenario. Final code:
$people_array = array(73227,970674,17293);
$args = array(
'taxonomy' => 'people',
'meta_query' => array(
array(
'key' => 'person_id',
'value' => $people_array,
'compare' => 'IN'
),
)
);
$people = get_terms( $args );
I am looking for the same solution. Even more, I’m looking for a way to get custom fields into the “create category popup”. Is there anything new half a year later?
@toniojst
There is a feature Request for ACF Extended: https://trello.com/c/WKVxUqm0/258-taxonomy-taxonomy-terms-add-new-term-modal-display-the-whole-add-term-page-in-modal
If this feature is implemented at some day, this would probably be a solution. However, I would prefer if there was a functionality like this implemented as a core feature in ACF. I don’t want to have to install an additional plugin because of a single extension.
@hube2
Is there a way to replace the + button with a target=”_blank” link, to open the standard “Create category popup” in another popup? This would help a lot. That would help a lot. We could insert a new entry via the standard form and search for it in our ACF. The content is always loaded from the database via Ajax. So we are able to find our new entry without refreshing the page. Or am I wrong?

Taxonomy fields contain Term IDs and Relationship fields use Post IDs. They are not interchangeable. There would still need to be some means to connect one with the other.
Hi John,
Thank you for your reply. I will look into the acf/load_value filter see if I can make it work.
I was wondering if it might be easier to use WP All Import plugin to export the old taxonomy selections and then import it into the ACF relationship filed.
regards
Karen

add_filter('acf/location/rule_types', array($this, 'my_acf_location_rule_types'));
function my_acf_location_rule_types($choices) {
if (!isset($choices['Other'])) {
$choices['Other'] = array();
}
if (!isset($choices['Other']['post_level'])) {
$choices['Other']['taxonomy_form'] = 'Taxonomy Form';
}
return $choices;
}
add_filter('acf/location/rule_values/taxonomy_form', array($this, 'acf_location_taxonomy_form_values'));
function acf_location_taxonomy_form_values($choices) {
if (empty($choices)) {
$choices = array();
}
if (!isset($choices['taxonomy_list'])) {
$choices['taxonomy_admin'] = 'Taxonomy Admin List';
}
if (!isset($choices['taxonomy_list'])) {
$choices['taxonomy_edit'] = 'Taxonomy Term Admin';
}
return $choices;
}
add_filter('acf/location/rule_match/taxonomy_form', array($this, 'acf_location_taxonomy_form_match'), 10, 3);
function acf_location_taxonomy_form_match($match, $rule, $options) {
$current = 'taxonomy_admin';
if (isset($_GET['tag_ID'])) {
$current = 'taxonomy_edit';
}
switch ($rule['operator']) {
case '==':
$match = ($current == $rule['value']);
break;
case '!=':
$match = ($current != $rule['value']);
break;
default:
// do nothing
break;
}
return $match;
}

If I am understanding correctly. I would create an options page. On this I would create a taxonomy field for tags. On this options page I would select all of the active tags. Then when I get the field from acf I would use an acf/fields/taxonomy/query filter to filter out (or filter “IN” with “include” argument) so that ACF only returns active terms.

You cannot have both an ACF taxonomy field that saves/loads value and the standard WP meta box for the taxonomy at the same time. Whichever one is processed last will override the one that is processed first. If you are going to have a taxonomy field to do this then you need to set the metabox callback for your custom taxonomy to false.
Another thing that can cause this is having taxonomy fields is repeaters or flex fields. This will not work with save/load terms for the same reason you can’t have the taxonomy field and the standard WP metabox. Whichever one is process last will override whatever is in the ones that are processed first.

The only way that you can do this is if there is some connection between the old taxonomy and the new post type.
If this connection exists or if there is some data in each that can be relied on that can be used, for example if you can guarantee that post slug and the term slug will match. Otherwise you may need to add a taxonomy field to the new post type to select the old taxonomy so that you have some kind of a connection.
If this connection can be made then I would create an acf/load_value filter for the relationship field. In this filter, if the value is empty then I would get the value of the old taxonomy field, get the posts related to that term and populated the value of the relationship field with the array of IDs that this returns.

I found some older topics that may help
https://support.advancedcustomfields.com/forums/topic/custom-location-rule-for-custom-taxonomy/
https://support.advancedcustomfields.com/forums/topic/custom-location-rule-for-taxonomies/
https://support.advancedcustomfields.com/forums/topic/custom-location-rules-for-an-specific-taxonomy-term/
https://support.advancedcustomfields.com/forums/topic/custom-rule-for-any-term-within-a-taxonomy/

There has never been, to my recollection, a custom taxonomy term location rule.
This would need to be added by creating custom location rules.
I don’t have any examples and can not find any for this specific case.

In order to have that appear the user type that is logged in must have the capabilities to manage (add) terms in that taxonomy. This is something that can be added with a user role editor plugin.

Some tips.
When working on a dev site, let’s say that you create a custom post type, add a bunch of field, populate a some content for testing. Then you decide that you want to delete this post type. You should not just delete the post type. This will not remove the posts from the database of any data associated with the posts. The first step is to delete all of the posts. Move them to trash and then delete permanently. This will cause WP to remove the posts from the DB and all associated meta data.
The same is true of custom taxonomies. But if you crate custom taxonomies for your custom post types then the first step before deleting the posts is to delete all the terms in the custom taxonomy and then delete the posts and finally delete the post types and taxonomies.
However, event with the old posts and fields in the DB, since these posts and fields will never be queried then they should not slow things down.
If you just delete fields without deleting the post types and taxonomies they are attached to or if you delete fields on options pages then any data entered into the fields will linger.
As far as slowing down the DB. This has been asked often. Having unused data in the DB will not in and of itself cause queries to be slow. Queries on meta data almost all of the time include something like “meta_key = your_field_name”. The meta_key field is and indexed row in the DB. The DB will not look even look at the fields that are left behind when performing these queries. There would need to be many, many (hundreds or thousands, or more) of unused fields in the DB to significantly effect the performance of the index. Queries that will cause and impact are those that are searching the “meta_value” without included a “meta_key” and the worst of these are “LIKE” queries on the “meta_value” without including the “meta_key”, but as long as the “meta_key” in included the extra fields are just ignored. In addition, any “LIKE” query is a query that will be suspect in site performance. When building a site this should be taken into consideration and alternatives should be explored. That said, most searching plugins that add custom fields to standard WP search ARE doing “LIKE” queries on the meta_value field without a meta_key and these search plugins will get slower.
The field is added to a custom taxonomy. Every post will have only one custom taxonomy term applied to it but there are a few options of custom taxonomy that would be applied based on the post type.

https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-result/
You can return an image tag in $text
Sorry, previously I created a custom post type named “article” and a custom taxonomy (category) named “article layout” with a custom image field as the image for the layout created using ACF pro.
Then, i created a custom field for the “article” custom post type, the field is a “taxonomy field” with select from the “article layout” custom taxonomy and save the single select as the category taxonomy.
When i create or add a new article custom post, the custom taxonomy display the custom “article layout” name.
My question is, how can i populate or add the custom image field in the “article layout” to the selection (instead only the name).
I hope its understandable, and thank you for the reply.
Pro subscriber here
Agreed, relating this to the Term id is not very transferrable between sites – being able to choose “taxonomy term == ‘term-slug'” would be preferable

Without querying the DB directly there really is not any way to group post by its terms.
You would need to
1) Get the Post IDs in the relationship field.
2) Get a list of all of the terms
3) Do a query with a tax_query for each term and use the post IDs returned in #1 in the “post__in” argument
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.