Not sure why you made your comment private.
Like I said, I don’t know anything about building custom walkers and I don’t know why it would not be working.
As far as my knowledge goes, when using a select field for taxonomy terms is that ACF calls wp_list_categories() and one of the filterable arguments for this function is ‘walker’.
The best I can do is tell you how to see if your filter is being called. For this turn on WP Error Logging and then call the PHP function error_log() inside of your filter and see if your messages is logged. This is the only way to tell because it is a AJAX request. Your filter will only run when you click into the field and ACF tries to load more choices.
If you want to possibly get input from someone other than me then you need to make your comment public, but it reality, your best choice for information on building a custom walker for WP is probably not this forum.
Another issue that could be causing this is that something is outputting something, and this could even be just white space, before ACF sends a response to the AJX request. Issues of this kind are extremely difficult to track down. It can be a plugin conflict or something in the theme, any filter or action that might run during the ajax request could cause it.
Another issue that could cause this is an extremely large number of terms in the taxonomy.
See my answer here https://support.advancedcustomfields.com/forums/topic/tweak-taxonomy-select/#post-163692
ACF calls the function wp_list_categories() to show a select field for taxonomy fields.
To alter the display of the select field you must build a custom walker.
You can alter the walker used by the field using the filter on acf/fields/taxonomy/wp_list_categories
$args['walker'] = new YourCustomWalkerClass();
Beyond this I can’t really help you much.
Here is one tutorial https://phppot.com/wordpress/wordpress-custom-walker/
many more can be found by searching the web for “wp_list_categories custom walker”
The correct link would be
"{$domain}/{$taxonomy_slug}/{$term_slug}/feed/"
There is not URL for categories of a specific post type
But you might be able to use
/feed/?post_type=news&category_name=featured
That is a very old example and what you are seeing is why I used select fields instead of ACF Post Object, Relationship or Taxonomy fields in that example. The only reason I created that repo was to post examples from work that I’ve actually done for clients.
Since I built that ACF has added the select2_ajax_data filter hook to the JS API. This filter can be used to get the value selected in another field and pass it to the server in ACF’s AJAX request used to populate the fields I mentioned above. You can then get that value from $_POST in one of the ACF server side query filters (acf/fields/relationship/query, acf/fields/post_object/query, acf/fields/taxonomy/query, acf/fields/taxonomy/wp_list_categories) to modify what is shown by ACF.
Unfortunately, I don’t have any examples of this because I have not found a reason to build them and would not rebuild old code unless it stops working.
This document covers getting values from a term https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
You are doing that incorrectly
$image_id = get_field(‘_thumbnail_id_marque’, ‘term_’ . $term_id);
you can also call this function with the term object instead of "term_{$term_id}"
This document covers using an image field https://www.advancedcustomfields.com/resources/image/
How you use it depends on what you have set as a return value for the image field. But you can always get only the ID value regardless of the return setting by setting the 3rd parameter to false
$image_id = get_field(‘_thumbnail_id_marque’, ‘term_’ . $term_id, false);
Hi,
Sorry for that misunderstanding, I’m working on woocommerce and the plugin “WP Gridbuilder”.
And a php code is exactly what I’m looking for !
So far I’ve done this :
function save_acf_image_as_featured_in_taxonomy($term_id) {
// Assurez-vous de remplacer ‘nom_du_champ_image’ par le slug de votre champ ACF
$image_id = get_field(‘_thumbnail_id_marque’, ‘taxonomy_’ . $term_id);
if ($image_id) {
// Enregistrez l’ID de l’image dans les métadonnées de la taxonomie
update_term_meta($term_id, ‘featured_image_id’, $image_id);
}
}
add_action(‘edited_ma_taxonomie’, ‘save_acf_image_as_featured_in_taxonomy’);
add_action(‘create_ma_taxonomie’, ‘save_acf_image_as_featured_in_taxonomy’);
function set_custom_card_thumbnail_for_taxonomy($object) {
// Obtenez les paramètres du grid courant.
$grid = wpgb_get_grid_settings();
// Si cela ne correspond pas à l’ID du grid 6.
if (6 !== $grid->id) {
return $object;
}
// Si l’objet est une taxonomie (ajustez ‘ma_taxonomie’ pour votre taxonomie).
if (is_a($object, ‘WP_Term’) && ‘marque’ === $object->taxonomy) {
// Obtenez l’ID de l’image ACF pour la taxonomie.
$image_id = get_field(‘_thumbnail_id_marque’, ‘taxonomy_’ . $object->term_id);
// Si un ID d’image est trouvé, affectez-le.
if (!empty($image_id)) {
$object->post_thumbnail = $image_id;
}
}
return $object;
}
add_filter(‘wp_grid_builder/grid/the_object’, ‘set_custom_card_thumbnail_for_taxonomy’);
But it’s not working…
I was poiting out the product category miniatures of woocomerce because, without any dev, it just works fine with what I’m willing to do.
Thanks.
Hello,
Thanks for your answer.
I do build on Woocommerce and it seems to me that the product category, witch is a wp taxonomy, has the featured image.
Anyway I’ve ask the gridbuilder support.
To be continued…
Hate to be a downer, but this is going to be difficult.
Given what you have you will need to do something like this: https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/
I would likely have made the “Books” CPT and then used child posts to create the “Editions” and separated the custom fields between parent/child posts based on what they applied to. This way you could show child posts on the parent post CPT and you could query all child posts by the “Type” taxonomy page (template: archive-{$taxonomy}.php} to show lists of books for each type.
This will work the same way whether using blocks or not using blocks.
To summerize and make sure I’m not missing anything.
You have two fields in your group
And you want to filter the posts available for selection in the post object field by the selected term.
This is not possible without custom coding. You will need to add custom JavaScript to ACF and you will need to use the ACF JS API.
In your JS code you will need to use the select2_ajax_data hook and get the value selected in the taxonomy field and add it to the values submitted in the AJAX request.
Then in your acf/fields/post_object/query filter you will need to get this value from $_POST and use the value to alter the query done for the post object field.
You may also need to trigger a refresh of the post object field or delete any value that is already selected in the post object field if the term selected in the taxonomy field is changed. I don’t have any references on how to do this part.
Hi,
This is awesome !
Is it possible to do the same with custom taxonomy ?
because if I add page type with or without child / parent it doesn’t work as it is not a page but a taxonomy.
I still don’t understand WHAT specifically these groups are.
Or you don’t know and you are asking how someone would do this? It could be done an any one of these ways.
I don’t know what you mean by
assign them to one or more user groups
Is this an ACF field? What type of field? A user Role? A taxonomy? A post?
Unless you’re doing something special then it should be as easy as adding the field group to the WP registration form by setting the field group location rules.
I can’t tell you how to use “ACF: Better Search”. This is a plugin by another developer and I do not use it.
What I do know is that you cannot alter the “s” parameter in the WP search to include searching a post based on a taxonomy.
You would need to have a separate field that listed the terms in the taxonomy where the value submitted is the term_id for each term. Then you would need to alter the query done during the search to add a tax_query.
This has nothing to do with adding the taxonomy, you would find these settings in the taxonomy “field” when adding a field to a group. As I said, ACF cannot control what the standard WP taxonomy meta box can do. You have to remove it and use an ACF field instead.
I thought you were using moving terms from one taxonomy to another. Post values will not be affected.
In all cases the meta key is the same as the field name.
The taxonomy field has the option of using a radio button for presentation
Sorry for the dumb question, but how can this be done?
I can’t find this option in the configuration for a custom taxonomy.
In a test site, I managed to do this with the help of a third-party plugin. But I can’t see a way to do this within the ACF settings for a custom taxonomy.
I didnt understand your reply.
I can already search any of those advanced custom fields set up the the ACF Pro plugin in the main search on wordpress. This was achieved by setting up the fields and setting the taxonomy as Product Visibility and then installing the plugin: “ACF: Better Search”
So in one of the ACF fields I have dates, if I enter a date from one of those fields in the main search it will find the product that has that date in the ACF field.
I now wish to refine that search to be able to check for searches that also match the search keyword plus the advance custom fields that I set up.
Avada Support told me that it was possible with your plugin:
“Every search parameter like category/tags has to be a taxonomy. For this to work, you will need to add custom taxonomies via a plugin like ACF”
But they dont offer support in how to do it, which is why im asking here
Do you plan to use a new CPT to show animals instead of WC? Allowing them to continue editing in WC and using another CPT would mean you’d need to duplicate all of the existing posts and also duplicate and/or update the related CPT every time something is added/edited/deleted. This really would be more work than just building a new site.
You could replicate most of it, but you can’t replicate the WC attributes without a lot of work. WC is special in that each “Attibuted” is a taxonomy that is created on the fly in the admin. They are basically nested taxonomies. Each “Term” in the “Attributes” is actually a custom taxonomy and attribute value is a term in the custom taxonomy.
I hate to be the bearer of bad news but the only way to move out of WC would be to build a new site. I imagine that whoever built this used WC to reduce the amount of work that would be needed or that they were not able to do all the custom coding that would be required.
There is no automated way to move the data from one to the other.
Data is stored in the _termmeta table by the term_id. When you create a new “category” this is a new term with a new term_id even if the name/slug is the same as the original “tag”.
Moving the data would require doing an DB search for all the _termmeta connected to the old term_id and replacing it with the new term_id.
You could, potentially, use the WP create_term hook. In the hook you could search the tags for a matching slug and then copy all of the ACF fields using get_field() and update_field(). Note that you will need to use the field keys to do the update process and NOT the field names.
add_filter('acf/format_value/field_name=YOUR_FIELD_NAME_HERE', 'YOUR_FUNCTION_NAME_HERE', 20, 3);
YOUR_FUNCTION_NAME_HERE($value, $post_id, $field) {
$terms = wp_get_post_terms($post_id, 'YOUR_TAXONOMY_HERE');
if (!is_wp_error($terms) && !empty($terms)) {
foreach ($terms as $term) {
if (get_field('YOUR_FIELD_NAME', $term)) {
$value = get_field('YOUR_FIELD_NAME', $term);
}
}
}
return $value;
}
When you are editing the “location” post can you see both your ACF taxonomy field and the default WP taxonomy meta box? Are you using “Save” and “Load” terms?
Please provide more detail.
ACF currently does not allow field groups locations by taxonomy term. The ACF Advanced plugin Pro version has this. It is often requested. I would suggest contacting the devs to add this feature https://www.advancedcustomfields.com/feedback/
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.