I’m trying to get a taxonomy field populated from the result of a selection in another field.
I’ve use https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example as a template and got most of it to work – but I can’t figure out how to append the info to the taxonomy field. It’s a select2 combobox and I can figure out how to it.
This is my .js
Hi newbe here. I have a simple question, unfortunately I couldn’t find the answer anywhere. I’m testing the free version of ACF and I have a problem with WP taxonomy (tags). The tag does not list the archive of content created in ACF. Taxonomies created in ACF work flawlessly.
I have an acf that takes the woocommerce products (which are not translatable, so there is only the italian version), this is the structure:
acf_add_local_field_group(array(
'key' => 'group_65017e7235881',
'title' => 'Home CPO',
'fields' => array(
array(
'key' => 'field_65017e798dde7',
'label' => 'Orologi in evidenza',
'name' => 'orologi_in_evidenza',
'type' => 'repeater',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'collapsed' => '',
'min' => 0,
'max' => 0,
'layout' => 'table',
'button_label' => '',
'sub_fields' => array(
array(
'key' => 'field_65017e8a8dde8',
'label' => 'Orologio',
'name' => 'orologio',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'product',
),
'taxonomy' => array(
0 => 'product_cat:rolex-cpo',
),
'allow_null' => 0,
'multiple' => 0,
'return_format' => 'object',
'ui' => 1,
),
),
),
),
'location' => array(
array(
array(
'param' => 'page_template',
'operator' => '==',
'value' => 'index-cpo.php',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
If I use the italian language, then the repeater will display all the products available. Otherwise, if I switch to english language the repeater doesn’t show anything.
This issue is kinda weird ’cause in the english version I can see all the products from the woocommerce dashboard but not from the repeater.
I’m trying to change the lang parameter that is sent from the ajax request of acf, so I did this:
function customize_acf_query($args, $field, $post_type)
{
$args['lang'] = 'it';
return $args;
}
add_filter('acf/fields/post_object/query', 'customize_acf_query', 10, 3);
but again, the acf doesn’t display any products. Could someone help me?
Thanks in advance!
Hi
i got prob to query users with custom field repeater
What i made :
i got a custom search form, who search in ajax with get_users and with complexe request on many user’s customs fields
all work fine, even filter taxonomy assigned to user like custom field
but it dont work for my repeater field..
the repeater key is : liste_des_langues & the item key : langue
if add this :
function wpza_replace_repeater_field( $where ) {
$where = str_replace( "meta_key = 'liste_des_langues_$", "meta_key LIKE 'liste_des_langues_%", $where );
return $where;
}
add_filter( 'posts_where', 'wpza_replace_repeater_field' );
and this is my request args for this field :
if($langues && $langues != 'all'){
$temp = array(
'key' => 'liste_des_langues_$_langue',
'value' => $langues,
'compare' => 'LIKE',
);
array_push($request['meta_query'] , $temp);
}
this is the basic request :
$request = array(
'role__in' => array( 'consultant' ),
'meta_query' => array(),
'tax_query' => array(),
);
if(count($_GET) > 1){
$request['meta_query']['relation'] = 'AND';
}
but it doesn’t work :/
and i dont understand where is my mistake, someone can help please ?
I have a custom post type which contains a custom taxonomy. I would like to make it so that a user cannot save their post unless they have chosen a value for this custom taxonomy. I expect them to use the admin interface to create their post. Is this possible? Thanks.
I’m facing an issue with custom fields for users, even though I think that’d happen for posts too.
I have a group “custom_fields” and within this group, there’s a multi-select whose key is “user_lang_spoken”.
This multi-select is pulling a custom taxonomy and it will return a list of term IDs.
Ok, so far so good and easy to understand. This is my custom loop to pull users:
$speaks = 5; // 5 = Spanish (That's the term name)
$args = array(
'fields' => 'ids',
);
if ($speaks) {
$args['meta_query'][] = array(
'key' => 'custom_fields_user_lang_spoken',
'value' => $speaks,
'compare' => 'LIKE',
);
}
$members = get_users($args);
#1 – You’ll see that I’m using ‘value’ => $speaks, and this is pulling all users who speak language 5 or language 55 (which is not ideal). This could actually work if it wasn’t numbers because we wouldn’t have a partial match, but I need them as IDs.
#2 – However, I found another topic where you guys say it returns serialized data and you recommend wrapping the value with quotes: ‘value’ => ‘”‘.$speaks.'”‘, and this is true, I’ll retrieve only users who speak language 5, but for that I need to MANUALLY update the user in the admin (without changing anything). Otherwise, I wont be able to see the user in this case.
I think this is an actual issue, it won’t happen often because people may be returning strings instead of IDs and by doing that, the chances of a partial match is rare. Also, if they are using IDs, they might have different IDs such as 2918, 9812, 5839… which again, would be rare.
However, that partial match will happen with lower numbers: 1 -> 12, 3 -> 32…
I don’t know what else to do, I tried some work around to force a user update on the frontend but it doesn’t seem to have the same impact as manually clicking on “Update user”.
Thanks!
Hi all, I’m using the ACF field to create and manage my custom post types
So far i have created an ACF with multiple groups and multiple fields inside those groups.
The ACF is displayed on a form on front-end and the posts are stored correctly under my custom Taxonomy.
The issue I’m facing is while displaying the Single Post, where I cannot present any of the custom fields but only title/author/date.
I found a YT video [07:55] that demonstrates how to add a ACF Field using the Theme Editor
But for me the ACF Field is not present there! Is it because of my Theme – Blocksy, or could it be due to another reason?
ACF Pro should support “Conditional Logic” settings based on the selection in a Taxonomy field, but it does not. ACF support advises that this does not currently work and advised that I post here. Please vote for this improvement!
Here’s an example:
In the fields for a CPT called “Bio”, I have a Taxonomy field called “Position”. It displays as three checkboxes. It uses a custom taxonomy called “Bio Type” with these three terms:
Actor (tag_ID for this term is 19)
Crew (tag_ID for this term is 20)
Musician (tag_ID for this term is 21)
(Note: the terms in the custom taxonomy are identified as “tag_ID”.)
I have another field (a text field) called “Role”.
I only want the “Role” field to be visible if the checkbox for Actor (tag_ID 19) has been selected.
In the “Conditional Logic” tab of the “Role” field, I have…
Show this field if
Position | Selection is greater than | 18 (and)
Position | Selection is less than | 20
“Conditional Logic” settings based on the selection in a Taxonomy fieldag_
Sadly, this does not work!
This is the way this works with other types of content, but custom taxonomies are not currently supported. I’d imagine that, since this works for other types of content (for example, post categories) where the term is identified by TERM_ID, it would not be too hard to extend this to tag_ID.
ACF will only implement this if it gets votes here; please help by liking this.
Hi all, I have created an ACF Block that uses a wp_query to display a filterable list of all posts of a specific post type. My issue is that I need to be able to add more than one of these blocks to a page, but when I do, I get a critical error. If I remove the wp_query, the page will load with multiple instances of the block. Anyone have any idea what I am doing wrong? My assumption is that I need to make the wp_query unique to the block instance, but I do not know how. Any help would be greatly appreciated.
The code is pretty large so I will just include my wp_query.
$args = array(
'post_type' => 'partners',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $partner_type,
'operator' => 'IN',
),
),
);
if ($grid_hosts_weddings) {
$args['meta_query'][] = array(
'key' => 'hosts_weddings', // ACF field key for hosts_weddings
'value' => '1',
'compare' => '='
);
}
if ($grid_hosts_meetings) {
$args['meta_query'][] = array(
'key' => 'hosts_meetings', // ACF field key for hosts_meetings
'value' => '1',
'compare' => '='
);
}
$partners_query = new WP_Query($args);
Hi,
Something very weird.
I made some custom functionality to make it happens the way I need, I’ll write here all the flow:
– I have created a new custom post type called event
. I also created a custom taxonomy under event
called event_type
.
– I created from GUI a field-group with tabs and in every tabs there are custom fields.
– In one of the tabs(last of them) there is a repeater and a sub-repeater.
– Inside this sub-repeater there is a group, and under this group(let’s call it specific-event
), I have SELECT field which I populate all terms from the custom taxonomy event_type
.
– I want that in the SELECT under the specific-event
, when the user picks a term, it will show custom group under specific-event
with custom fields.
So what I did:
I have created programmatically each group and set the parent
attribute to be specific-event
field key.
Each group automatically gets ‘hidden’ class.
In the JS API, I have created some logics, to detect any term select and make the correct group(I have created programmatically) to be visible.
– So far all good, the custom functionality seems to be working,
Everytime I change the term in the select under specific-event
it shows me the correct sub-group under specific-event
.
BUT, when I add lets say 7 parent rows in the parent repeater, and inside I add more 3-4 sub-rows each,
It doesnt save all… after saving I gets only 4 parent rows, and not 7. Something very very wierd.
This is the code for the custom groups:
add_action('init', function() {
if (function_exists('acf_add_local_field_group')) {
acf_add_local_field(array(
'key' => 'field_event_event',
'label' => 'נקודת עניין',
'name' => 'event__event',
'aria-label' => '',
'type' => 'select',
'choices' => array(),
'return_format' => 'array',
'ui' => 1,
'multiple' => 0,
'parent' => 'field_6441222b20c40'
));
acf_add_local_field(array(
'key' => 'field_event_time',
'label' => 'זמן',
'name' => 'event__time',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'taxonomy' => '',
'parent' => 'field_6441222b20c40'
));
$event_types = get_terms([
'taxonomy' => 'event_type',
'hide_empty' => false,
]);
foreach ($event_types as $event_type) {
$dynamic_fields = (!empty(TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id)) ? TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id) : array());
$field_group = array(
'key' => 'field_' . $event_type->term_id,
'label' => $event_type->name,
'name' => 'event__type-' . $event_type->term_id,
'type' => 'group',
'wrapper' => array(
'class' => 'hidden',
),
'parent' => 'field_6441222b20c40'
);
foreach ($dynamic_fields as $dynamic_field) {
$field_group['sub_fields'][] = array(
'key' => 'field_' . $dynamic_field['dynamic-fields__system-name'],
'label' => $dynamic_field['dynamic-fields__name'],
'name' => 'type-' . $event_type->term_id . '__' . $dynamic_field['dynamic-fields__system-name'],
'type' => $dynamic_field['dynamic-fields__type']['value'],
);
}
acf_add_local_field($field_group);
}
}
});
I have a website about movies. I have created a taxonomy Actors and added 2 custom fields via ACF “website” and “imdb link” and i use the standard field “description”
When i add e.g. the taxonomy Tom Hanks, I head over to ChatGPT to ask for one paragraph on Tom Hanks, his website and his imdb link. I copy the results manually to to the term fields.
The process is the same for each actor, as the process is a repetitive task, it should be able to be automated. I do have an active OpenAI account so i can use the API when needed.
Do you guys think it would be possible to pull the information automatically from OpenAI and store it?
As I am not a skilled programmer, any tips or directions on where to start would be appreciated.
Hi there,
I need help in showing the ACF fields that I’ve created in WooCommerce Add New Product Page for a specific category only. That specific category would have some sub-category and I would like to include those as well. I can’t choose Post Type as Product because I have different fields customized for different product category.
Currently, I could only make it to show in the Edit Product Page. If I choose the location rules as Post Taxonomy for a certain product type or product cat, then it’ll only show those ACF fields in the Edit Product Page as that particular post is published, and so it has its own taxonomy queried. However, before the post is published (add new product page), it would not show since it doesn’t have any taxonomy query yet.
Is there anything that I can set to make this work or any advice on this? Would appreciate very much for the help given. Thanks
Is it possible to show a field only on the top-level taxonomy? I have a taxonomy hierarchy like this:
– Courses
— Arts
— Drawing
I want to show a field from a field group only on ‘Courses’.
If that’s not doable, I would also be happy to create a separate field group and display this only on the top-level taxonomy. Would that be doable?
I have created a field group which is set to be visible for Taxonomy if it’s equal to Tag (post_tag). I can see the field with it’s default value when editing tag but I can’t get that value in my code. I always get it returned as null.
How I’m trying this field value:
$term = get_queried_object();
$field_value = get_field('tag_', $term->term_id, 'about_schema');
I tried var_dump($term) and it returns me this:
object(WP_Term)#8411 (10) { ["term_id"]=> int(7346) ["name"]=> string(13) "Hedera (HBAR)" ["slug"]=> string(11) "hedera-hbar" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(7346) ["taxonomy"]=> string(8) "post_tag" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(12) ["filter"]=> string(3) "raw" }
In this var_dump I can’t see the values added from ACF field.
What I’m doing wrong here?
Is it possible to set up CPT & taxonomy like this:
/archive-for-the-CPT/ – the archive page
/archive-for-the-CPT/%category-name%/ – the category page under the CPT & archive
/archive-for-the-CPT/%category-name%/%postname%/ – the actual post/url
I am struggling hard to work this out. Assuming a permalink rewrite plugin is needed here?
Thanks in advance.
Hello, I made a Custom Taxonomy for a site I’m building, and it does everything it should but the field can’t be edited in the “Edit Post” Gutenberg sidebar. It doesn’t show what the current custom taxonomy of the post is and doesn’t save any changes. The custom taxonomy is working right in the quick edit view, as it can be edited and saved using this option.
The custom taxonomy is used for managing Guest Authors, and they even show right in the front-end.
I have an incomprehensible problem, which is with custom taxonomies, I created a custom taxonomy named “teams” using the following code:
function add_post_taxonomy() {
$taxArray = array(
array(
"taxName" => 'Teams',
"taxNameEn" =>'teams'
),
);
foreach ($taxArray as $tax) {
$labels = array(
"name" => __( "", "" ),
"singular_name" => __( $tax['taxName'], "" ),
"menu_name" => __( $tax['taxName'], "" ),
);
$args = array(
"label" => __( $tax['taxName'], "" ),
"labels" => $labels,
"public" => true,
"hierarchical" => true,
"label" => $tax['taxName'],
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"show_admin_column" => false,
"query_var" => true,
"rewrite" => array( 'slug' => $tax['taxNameEn'], 'with_front' => true, ),
"show_in_rest" => true,
"rest_base" => $tax['taxNameEn'],
"show_in_quick_edit" => true,
);
register_taxonomy( $tax['taxNameEn'], 'matches', $args );
}
}
add_action( 'init', 'add_post_taxonomy' );
And I created a function to get the custom terms as follows:
function get_terms_for_acf_select() {
$terms = get_terms(array('taxonomy' => 'teams', 'hide_empty' => false));
$options = array();
if (is_array($terms)) {
foreach ($terms as $term) {
if (is_object($term)) {
$options[$term->term_id] = $term->term_id;
}
}
}
return $options;
}
The problem is when I use it like this to get options, I don’t get anything
acf_add_local_field_group(array(
'key' => 'group_team_data',
'title' => 'team Data',
'fields' => array(
array(
'key' => 'field_team_info',
'label' => 'teams',
'name' => 'teams',
'type' => 'select',
'instructions' => 'Select the team',
'choices' => get_terms_for_acf_select(),
'return_format' => 'value', // Change 'label' to 'value'
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'matches',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
));
}
Knowing that when I change teams to categories, it works normally
I’m using the acf_form() function to allow certain users to submit data (new posts) to my website.
I’m using the taxonomy field type in the radio button variant but I can’t figure out how to define a “default” case. It is possible when using the radio button field type but not when using the taxonomy field type.
Any clue on how to do this?
When you add a custom taxonomy to a field group, two options are unselected by default:
Save Terms. I’ve discovered through trial and error that you must have this selected in order to access a “list of terms” in my platform of choice (GenerateBlocks Pro and GeneratePress Pro).
Load Terms. Can’t figure out what this one does. Documentation is no help. I’m sure it’s fairly simple, perhaps even obvious. But can you set me straight?
Hi ACF Team,
I am running a listing website using ACF Pro. A form enables users to add new entries and that form also displays the taxonomy (tags) field. Adding new tags in that front-end form is enabled, and if I am logged in as an admin user there is a little plus-sign appearing on hover.
However, that same plus sign isn’t shown once a user of any other role is using the same form. The following DIV is simply missing for such users:
<div class="acf-actions -hover">
....
</div>
How can I possibly make it work for anyone using the form, not just for admins?
Thanks, Ralph
I have a custom post type “Golf” with a taxonomy “Secteur”, I also associated this taxonomy to posts.
In my CPT “Golf” I have multiples entries (Golf #1, Golf#2 etc) with his propers terms, for example, Golf#1 has “Poitou-Charentes” for parent term and “La Rochelle” which is a child of “Poitou-Charentes”.
What i’d like is when the author of “Golf #1” publish a post, the taxonomy attributed to “Golf #1” is automatically given to this post and same for others Golfs.
Is it possible ?
I am having an issue where if using Quick Edit on my custom post type to change taxonomy selections, the grey spinning wheel appears when I click update and the whole process hangs.
If I edit an individual post and make changes there, everything is fine and I am able to save changes.
I did migrate from Custom Post Type plugin – but I wondered is there any setting that I am missing to be able to edit taxonomy terms in “quick edit”? Or, is it just not something I can do?
Thank you!
With ACF I’ve created a custom post type that has a custom taxonomy field (also created with ACF). In the custom post type I’m also using Gutenberg editor.
I’ve added the taxonomy field manually with a field group, but found that it is also present in the sidebar. I wanted to hide/remove the taxonomy from the sidebar, but I was not able to do it, even if I selected “No Meta Box” option at the “Visibility” tab of the custom field.
After hours and hours of struggling to find out what I did wrong, I found many Gutenberg-ACF-MetaBox related issues on different blogs, forums and GitHub, and these metabox hiding” of issues seems to be present for years.
However, I also found a GitHub comment from 2019 which – for me at least – actually provided a clean looking fix for this issue.
Here is the comment:
github . com /WordPress/gutenberg/issues/13816#issuecomment-470137667
And here is the code:
add_filter( 'rest_prepare_taxonomy', function( $response, $taxonomy, $request ) {
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
// Context is edit in the editor
if( $context === 'edit' && $taxonomy->meta_box_cb === false ){
$data_response = $response->get_data();
$data_response['visibility']['show_ui'] = false;
$response->set_data( $data_response );
}
return $response;
}, 10, 3 );
This code checks the taxonomies “meta_box_cb” property and allows modification of the taxonomy data right before it is returned from the rest API. And if the “meta_box_cb” is false, it sets “show_ui” of the metabox to false, so it will not show up in the sidebar.
This actually makes the “No Meta Box” option working with Gutenberg!
Is there any reason why this fix has not been implemented for four years?
Are you planning to implement it in the near future?
If not, at least it would be very important to add a note about this issue next to the “No Meta Box” option to save many hours of unnecessary debugging for the users.
Waiting for an official statement about this.
Best regards,
Zs
Hi, I created a new custom post type for cars in wordpress.
Now I plan to create a page for the list of brands using taxonomy or meta data, but I want to see the available series of this brand after the user enters the BMW page, and after entering the page of each series , view different generations of cars.
How can I connect 3 separate fields?
So that in the admin panel, something is the same as the system that exists in selecting the province and city in online stores. After selecting the province, a list of cities under that province will be displayed in the side form.
Is this possible in ACF?
example: https://www.car.info/en-se/brands
I wanted to do something like this in Taxonomy:
https://imgur.com/NIUHfos
I couldn’t find this option within Taxonomy > Advanced Settings. I can only see this in Post Types.