Like, through a custom taxonomy I have added this under-category which I can add stuff to. But I cannot in the documentation see what code to use to filter for “uses this taxonomy”. Is it a category? a product type?
Hi! Thank you!
However, I think I might have worded the questions wrong.
I’m working with code. On the front page for instance, I want to have a section which shows all of the names & images of all of my authors. How do I tell to pull of everything that is classified as this specific taxonomy?
How you do this depends on how you are building. If you are building a theme yourself then you need to add a template for “taxonomy-{$taxonomy}.php”, see WP Template Hierarchy.
If you are using a page builder then you need to see the documentation for that page builder for building an archive template.
Preventing this would be complicated.
You would need to add custom javascript to ACF and use the ACF JS API select2_ajax_data filter and include the values selected in the other fields to the AJAX request and then use an acf/fields/taxonomy/query or acf/fields/taxonomy/wp_list_categories filter to alter the the terms that are returned by the AJAX request for each field.
The only way to do that would be to have 3 different queries for posts based on the terms selected in each of the taxonomy fields.
Thank you @hube2 , that’s completely true!
In the meantime I found a solution that works for me. If anyone else needs it:
function update_post_taxonomy( $post_id ) {
$myfield = get_field('my_field_name');
if( $myfield ) {
wp_set_object_terms($post_id, 'myterm', 'mytaxonomy', true);
}
add_action('acf/save_post', 'update_post_taxonomy', 20);
Cheers!
If you are using the gutenberg editor then this is a know issue. Field groups will not automatically update based on taxonomy term selection and the post must be updated to trigger ACF to show the correct field group. The same is probably true when setting a default term for a post.
In your loop template, use the get_field() function to retrieve the custom field values for each term in the “product_categories” taxonomy. Here is an example code snippet:
<?php
$terms = get_terms( array(
'taxonomy' => 'product_categories',
'hide_empty' => false,
) );
foreach ( $terms as $term ) {
$name = get_field( 'c_name', $term );
$image = get_field( 'c_image', $term );
if ( $name ) {
echo '<h2>' . esc_html( $name ) . '</h2>';
}
if ( $image ) {
echo wp_get_attachment_image( $image, 'thumbnail' );
}
}
?>
This code snippet retrieves the “c_name” and “c_image” custom field values for each term in the “product_categories” taxonomy and displays them in the loop.
Ok i find solution i must append this popup before my offcanvas. So with this code $(‘#acf-popup’).prependTo(‘.offcanvas’) solve my problem in class-acf-field-taxonomy.php
It does not appear that this is a feature of ACF CPTs. You’ll need to contact the developer to see if they plan to add this https://www.advancedcustomfields.com/contact/
For now you would need to add action on the registered_post_type (https://developer.wordpress.org/reference/hooks/registered_post_type/) hook and call https://developer.wordpress.org/reference/functions/register_taxonomy_for_object_type/ in functions PHP on the registered_taxonomy hook.
I’m using the acf_form() function to allow certain users to submit data to my website (new articles).
https://support.advancedcustomfields.com/forums/topic/define-a-default-taxonomy-radio-button/ geometry dash scratch
Un grand salut aussi 🙂
Au cas où d’autres personnes rencontrent le meme problème on continue en Anglais ? 🙂
I am definitely not a coder/dev and since the latest release of ACF what I am trying, or anyway, achieved so far, has been done without a single bit of code.
My bad, I forgot to specify that I am also using Elementor.
But here is what I have done:
I have created a new taxonomy:
https://prnt.sc/SblxWOHBmACi
https://prnt.sc/QpWKI3Qa41-S
https://prnt.sc/A8kIAtrZXW6m
Salut aussi !
Au cas où d’autres personnes rencontrent le meme problème on continue en Anglais ? 🙂
I am definitely not a coder/dev and since the latest release of ACF what I am trying, or anyway, achieved so far, has been done without a single bit of code.
My bad, I forgot to specify that I am also using Elementor.
But here is what I have done:
I have created a new taxonomy:
Salut aussi !
Au cas où d’autres personnes rencontrent le meme problème on continue en Anglais ? 🙂
I am definitely not a coder/dev and since the latest release of ACF what I am trying, or anyway, achieved so far, has been done without a single bit of code.
My bad, I forgot to specify that I am also using Elementor.
But here is what I have done:
I have created a new taxonomy:
https://prnt.sc/SblxWOHBmACi
https://prnt.sc/QpWKI3Qa41-S
https://prnt.sc/A8kIAtrZXW6m
Salut aussi !
Au cas où d’autres personnes rencontrent le meme problème on continue en Anglais ? 🙂
I am definitely not a coder/dev and since the latest release of ACF what I am trying, or anyway, achieved so far, has been done without a single bit of code.
My bad, I forgot to specify that I am also using Elementor.
But here is what I have done:
I have created a new taxonomy:
https://prnt.sc/SblxWOHBmACi
https://prnt.sc/QpWKI3Qa41-S
https://prnt.sc/A8kIAtrZXW6m
And here is what I did in Elementor:
https://prnt.sc/kQmfuTbvomh1
So it definitely loads something correct, which is the ID of the taxonomy:
https://prnt.sc/2gf4eFlbn8tv
In this case 59
But even if I switch the value as showed in my original post this is still the ID and not the value/term that is showing up.
It works fine with “normal” fields:
https://prnt.sc/X–0v2gyJDCc
https://prnt.sc/GwSsYtf4DpfC
But I know this is not the same thing as Taxonomies.
And I am a bit stuck :-/
Salut aussi !
Au cas où d’autres personnes rencontrent le meme problème on continue en Anglais ? 🙂
I am definitely not a coder/dev and since the latest release of ACF what I am trying, or anyway, achieved so far, has been done without a single bit of code.
My bad, I forgot to specify that I am also using Elementor.
But here is what I have done:
I have created a new taxonomy:
https://prnt.sc/SblxWOHBmACi
https://prnt.sc/QpWKI3Qa41-S
https://prnt.sc/A8kIAtrZXW6m
And here is what I did in Elementor:
https://prnt.sc/kQmfuTbvomh1
So it definitely loads something correct, which is the ID of the taxonomy:
https://prnt.sc/2gf4eFlbn8tv
In this case 59
But even if I switch the value as showed in my original post this is still the ID and not the value/term that is showing up.
It works fine with “normal” fields:
https://prnt.sc/X–0v2gyJDCc
https://prnt.sc/GwSsYtf4DpfC
But I know this is not the same thing as Taxonomies.
And I am a bit stuck :-/
I even asked chatgpt to write me a code snippet which looks that it could have done something (I even asked the function to check on a specific url) but it still doesn’t work 🙁
Salut aussi !
Au cas où d’autres personnes rencontrent le meme problème on continue en Anglais ? 🙂
I am definitely not a coder/dev and since the latest release of ACF what I am trying, or anyway, achieved so far, has been done without a single bit of code.
My bad, I forgot to specify that I am also using Elementor.
But here is what I have done:
I have created a new taxonomy:
https://prnt.sc/SblxWOHBmACi
https://prnt.sc/QpWKI3Qa41-S
https://prnt.sc/A8kIAtrZXW6m
And here is what I did in Elementor:
https://prnt.sc/kQmfuTbvomh1
So it definitely loads something correct, which is the ID of the taxonomy:
https://prnt.sc/2gf4eFlbn8tv
In this case 59
But even if I switch the value as showed in my original post this is still the ID and not the value/term that is showing up.
It works fine with “normal” fields:
https://prnt.sc/X–0v2gyJDCc
https://prnt.sc/GwSsYtf4DpfC
But I know this is not the same thing as Taxonomies.
And I am a bit stuck :-/
I even asked chatgpt to write me a code snippet which looks that it could have done something (I even asked the function to check on a specific url) but it still doesn’t work 🙁
function convert_taxonomy_ids_to_terms( $value, $post_id, $field ) {
if ( ! $value ) {
return $value;
}
if ( strpos( $_SERVER[‘REQUEST_URI’], ‘/listing-des-animaux/’ ) !== false ) {
$taxonomies = get_object_taxonomies( ‘animaux’ );
if ( is_array( $value ) ) {
$text_values = array();
foreach ( $value as $id ) {
foreach ( $taxonomies as $taxonomy ) {
$term = get_term_by( ‘id’, $id, $taxonomy );
if ( $term ) {
$text_values[] = $term->name;
}
}
}
return implode( ‘, ‘, $text_values );
} else {
foreach ( $taxonomies as $taxonomy ) {
$term = get_term_by( ‘id’, $value, $taxonomy );
if ( $term ) {
return $term->name;
}
}
return $value;
}
} else {
return $value;
}
}
add_filter( ‘acf/format_value/type=taxonomy’, ‘convert_taxonomy_ids_to_terms’, 10, 3 );
Struggling with WooCommerce product filtering using taxonomies (“Model” and “Model Year”). The system fails to distinguish between models and assumes incorrect associations with model years.
Solutions:
Hierarchical Taxonomies:
Make “Model” taxonomy hierarchical.
Custom Taxonomy Structure:
Combine “Model” and “Model Year” into a single custom taxonomy.
ACF Relationship Field:
Use ACF Relationship field for flexible relationships.
Custom Meta Fields:
Implement custom meta fields for precise data control.
Custom Search Filters:
Build custom search queries considering both taxonomies.
Custom Code for Plugin:
Customize the Search & Filter plugin for specific taxonomy handling.
Developer Assistance:
Seek help from a developer for complex customizations.
@fzs, thanks for your bug fix inspiration!
Somehow in WP 6.4.2 it didn’t work for me.
When I removed $taxonomy->meta_box_cb === false
it worked, but for all categories on all post types.
But since I only want to hide a specific custom category, I simply replaced it with $taxonomy->name === 'event-category'
.
So the final modified version is this:
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->name === 'event-category' ){
$data_response = $response->get_data();
$data_response['visibility']['show_ui'] = false;
$response->set_data( $data_response );
}
return $response;
}, 10, 3 );
You have to supply the correct post ID when calling acf function to get values from terms. See this document https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
Ah yes the block is wrapped inside a
<?php
$case_study_category = get_field('case_study_category');
if( ($case_study_category) ) :
?>
...
<?php endif; ?>
The field is Taxonomy (Category)
Return Value: Term ID
Screen here of field page: https://postimg.cc/D4GNVRYQ
When is add_local_field_group called, before or after “init” when the taxonomy is added. I suspect that you are attempting to get the terms in the taxonomy before the taxonomy has been initialized.
function get_terms_for_acf_select() {
$terms = get_terms(array('taxonomy' => 'teams', 'hide_empty' => false));
if (is_wp_error($terms)) {
die ('WP Error Getting Terms');
}
$options = array();
if (is_array($terms)) {
foreach ($terms as $term) {
if (is_object($term)) {
$options[$term->term_id] = $term->term_id;
}
}
}
return $options;
}
yes there is, someone else commented on this but it was marked as spam because they included a spammy link. It’s sad when people who actually have knowledge post useful information only because they want to inject a link to some unrelated site. In all likelihood these people are now generating what appears to be useful information with AI. I do not put up with spam here.
Anyway
UPDATE wp_posts SET post_type = 'dog-something' WHERE post_type = 'dog'
This should be done with caution, like backing up your DB first.
Yes, you should plan ahead. Test a little if you want, but I would not change a CPT or custom Taxonomy name after live content is added. Especially if there is a lot of posts.
I have steered you wrong.
acf/fields/taxonomy/query is used for select fields and the select field does not use wp_list_categories()
Select fields are rendered using ACF’s select field rendering, the only way to alter the title is with acf/fields/taxonomy/result, if that does not work then it is not possible.
I’m now facing exactly this same issue https://support.advancedcustomfields.com/forums/topic/add_filteracffieldstaxonomyquery-bug/#post-30884 filter is not getting called.
I’m using WP 6.4.
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.