I have issue with inserting terms while typing select input field. Strings will be correctly inserted but if there is date or number values for terms then it inserts term ID.
I have a lot term fields and some of them are numeric fields like date, mileage, etc..
My Code:
function jl_insert_term_if_not_exists($term, $taxonomy) {
if (empty($term) || is_numeric($term)) { //tried is_string() then every value inserted as term ID
return $term;
}
if ($result = term_exists($term, $taxonomy)) {
return $result['term_id'];
}
$result = wp_insert_term($term, $taxonomy);
if (!is_wp_error($result)) {
return $result['term_id'];
}
}
function jl_acf_update_value( $value, $post_id, $field ) {
if ($field['type'] == 'taxonomy'
&& in_array($field['field_type'], array('select', 'multi_select'))
&& strpos($field['wrapper']['class'], 'acf-select-tags') !== false)
{
if (!is_array($value)) {
if ($term_id = jl_insert_term_if_not_exists($value, $field['taxonomy'])) {
$value = $term_id;
}
} else {
foreach ($value as &$item_value) {
if ($term_id = jl_insert_term_if_not_exists($item_value, $field['taxonomy'])) {
$item_value = $term_id;
}
}
}
}
return $value;
}
add_filter('acf/update_value', 'jl_acf_update_value', 5, 3);
function jl_acf_input_admin_footer() {
?>
<script type="text/javascript">
(function($) {
acf.add_filter('select2_args', function( args, $select, settings, $field, instance ){
if ($field.hasClass('acf-select-tags')) {
console.log($field.hasClass('acf-select-tags'));
args.tags = true
}
return args;
});
})(jQuery);
</script>
<?php
}
add_action('acf/input/admin_footer', 'jl_acf_input_admin_footer');
I’m trying to follow the docs with adding custom fields to a specific category but I’m just not getting what the same results as the screenshots.
I’m instructed to select:
Location -> Show this field group if -> Taxonomy Term and yet it’s nowhere to be found.
Selecting:
Location -> Show this field group if -> Post -> Post Category or Location -> Show this field group if -> Post -> Post Taxonomy give me no results, and Forms -> Taxonomy adds it to everything! (Category page AND custom Category)
Is there something that I’m overlooking?
Hi i need implement one field search, in field wp_list_categories() this is possible?
ex:
input search
cat
-cat2
–cat3
Howdy!
I have a custom taxonomy ‘Review Series” with a featured image custom field. In archive.php I want to set the header image to the image specified if one is provided. I can detect that the user is browsing the “review-series’ taxonomy and I can get the ID of the term but get_field causes WordPress to crash.
$archive_id = get_queried_object_id();
This set $archive_id to 22488, the appropriate term_id.
if get_field( 'review_series_featured_image', $archive_id ) {
$fanart = get_field( 'review_series_featured_image', $archive_id );
}
This is the code that causes WordPress to choke.
I know I can hunt through wp_postmeta to get the value myself but that seems like a lot of hoop jumping.
Any ideas?
Chris
ERROR: http://localhost/mensageria/wp-admin/admin-ajax.php
Hi i have a problem with acf/fields/taxonomy/query/key=field_62d02ad58c59f, because when call a function, my field show ERROR 500 in wp-admin/admin-ajax.php and my terms in list not show.
array(
'key' => 'field_62d02ad58c59f',
'label' => 'Clients',
'name' => 'clients',
'type' => 'taxonomy',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '25',
'class' => '',
'id' => '',
),
'admin_only' => 0,
'taxonomy' => 'cat_notice',
'field_type' => 'select',
'allow_null' => 0,
'add_term' => 0,
'save_terms' => 1,
'load_terms' => 1,
'return_format' => 'object',
'multiple' => 0,
),
add_filter('acf/fields/taxonomy/query/key=field_62d02ad58c59f', 'my_acf_fields_taxonomy_query', 10, 2);
function my_acf_fields_taxonomy_query( $args, $field, $post_id ) {
// Order by most used.
$args['parent'] = 0;
return $args;
}
Its my code is like exemplo in documention, but my field inside other field/repeater.
possible bug (Latest ACF, WP 5.9.2)
* set a condition for fields as Post Type = Some Post Type, Post Taxonomy = Some Value
* create a new custom post
* add the taxonomy Some Value to the post
=> observe the ACF fields will now appear automatically due to the taxonomy matching the condition
* enter some values into the ACF fields
* publish
* refresh the page
=> observe ACF field values are missing
can anybody else confirm this issue?
thanks
J
Hi, we’re using ACF to create custom Gutenberg blocks. In our theme (Sage 10) we are able to create variables that get passed down to each corresponding Blade file.
An example is a $currentState variable, which returns a taxonomy item based on the post that the current user is viewing.
That variable loads as expected on the front end. However, on the back end it throws an error as Gutenberg isn’t aware that $currentState exists.
Does anybody have suggestions for how to pass data of that nature to Gutenberg?
Thanks!
Hi
I’ve got a repeater field that I’m using to create multiple sections on a page. The repeater fields will control the title and content of a given field and the WP category that relates to it. The goal is the then call custom posts in that category to the section to display.
The loop that I’ve written for the repeater works and the array I’ve written for the posts works. But I can’t work out how to take the taxonomy result from the repeater and use that to determine what is outputted from the custom posts array.
Much googling and forum searching hasn’t turned up exactly what I’m looking for and I’m looking for help or advice to solve it.
Source code below.
Thanks in advance
<?php if( have_rows('theme_info') ): ?>
<?php while( have_rows('theme_info') ): the_row();
$title = get_sub_field('theme_title');
$id = get_sub_field('section_id');
$cat = get_sub_field('theme_category');
$themecontent = get_sub_field('theme_content');
?>
<div class="individual-theme-wrapper">
<div class="theme-intro">
<a class="anchor" id="<?php the_sub_field('section_id'); ?>"></a>
<p class="h1"><?php the_sub_field('theme_title'); ?></p>
<?php the_sub_field('theme_content'); ?>
</div>
<div class="theme-speakers">
<?php
$projects = new WP_Query([
'post_type' => 'bes_speakers',
'posts_per_page' => -1,
// 'cat' => ,
'order_by' => 'date',
'order' => 'asc',
]);
?>
<?php if($projects->have_posts()): ?>
<div class="bes-speakers">
<?php
while($projects->have_posts()) : $projects->the_post();
include('partials/bes-speaker-tile.php');
endwhile;
?>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
Hello,
I created a custom taxonomy, I added 2 ACF fields to it, in the back end everything works great. But in the front end I cannot fetch the ACF values.
$context['bankingoptions'] = wp_get_post_terms($post->ID, 'review_banking', array());
var_dump($context['bankingoptions']);
Will display below, notice there are no ACF values
/var/www/html/web/app/plugins/timber-library/vendor/twig/twig/src/Extension/DebugExtension.php:70:
array (size=3)
0 =>
object(WP_Term)[2220]
public 'term_id' => int 73
public 'name' => string 'Bitcoin' (length=7)
public 'slug' => string 'bitcoin' (length=7)
public 'term_group' => int 0
public 'term_taxonomy_id' => int 73
public 'taxonomy' => string 'review_banking' (length=14)
public 'description' => string '' (length=0)
public 'parent' => int 0
public 'count' => int 1
public 'filter' => string 'raw' (length=3)
1 =>
object(WP_Term)[2222]
public 'term_id' => int 74
public 'name' => string 'Mastercard' (length=10)
public 'slug' => string 'mastercard' (length=10)
public 'term_group' => int 0
public 'term_taxonomy_id' => int 74
public 'taxonomy' => string 'review_banking' (length=14)
public 'description' => string '' (length=0)
public 'parent' => int 0
public 'count' => int 1
public 'filter' => string 'raw' (length=3)
Hi there,
I’ve created a rule group for a custom field to appear only when the post is equal to product AND when the post taxonomy is equal to a product category.
I’ve got vendor allowed edits set to true.
It’s functioning as I would expect when I try to create a product in admin with woocommerce but not for the sellers in dokan product upload. The custom field is appearing for all products when I only want it to appear when the seller has selected a specific category.
I’m not sure what i’m doing wrong?
ps i’ve read other people having the same issues and I understand I need to add some javascript somewhere but i’m new to all this so if it could be explained what i do with this js and where to put it to get around this problem I would be very grateful.
Many thanks
I have a custom taxonomy called ‘Shows’.
I’m using the php below to show items from that taxonomy that also have the ACF field ‘podcast_country’ (type = text) populated with ‘Australia’.
This works perfectly in that case.
I also have an ACF field called ‘podcast_topic’ (type = taxonomy, appearance = multi-select, return value = Term Object). I would like to use a similar code block to retrieve items with the topic ‘educational’.
I cannot for the life of me work out how to do it. Other text fields work fine when checking against a single word, but when it comes to the taxonomy field I just get an empty screen – so clearly I’m missing something around that field type – but hours of searching and experimentation has gotten me nowhere.
What changes do I need to make to this to make it work with an ACF taxonomy field?
<?php
$madein = get_terms('shows',array('hide_empty' => 0));
echo '<div class="row mb-5"><div class="col-12"><h3>Made in Australia</h3></div>';
foreach($madein as $term)
{
if( get_field('podcast_country', 'shows_'.$term->term_id) != 'Australia' )
continue;
echo '<div class="col-6 col-md-3 col-lg-3 col-xl-2 p-2"><a href="' . get_term_link( $term ) . '">';
echo wp_get_attachment_image( get_field('podcast_category_thumb', $term), 'thumbnail', false, array('class' => 'img-responsive rounded','style' => 'width:100%;height: auto; aspect-ratio: 1 / 1') );
echo '</a></div>';
}
echo '</div>';
?>
Hi,
I’ve been struggling with this for days and Googled this to death! 🙁
Apologies in advance, if this is a really simple question.
Basically, I’m trying to add two ACF text values to a Taxonomy (Tag) page.
One is for the link value (page_link) and one is for the name of the link (page_name)
I’ve set up ACF so I’m able to add both these values on the Edit Tag (Taxonomy) page in WordPress
In my tag.php page I have the following line of code:
<a href="<?php bloginfo('url'); ?>/<?php the_field('page_link'); ?>"><?php the_field('page_name'); ?></a>
I hoped it would load the page_link and page_name values into this code.
When I view the page source in the browser, none of the ACF values are coming through?
I’ve managed to get ACF working on category, page, and posts – but for some reason, it doesn’t seem to work on Taxonomy / Tag pages?
I’m wondering if either this isn’t possible, or I need to add an extra step in the page code?
Or my ACF settings are incorrect:
In ACF for both fields, Location is set to: Taxonomy – is equal to – All
Both fields are active, set to Text, and published.
I hope someone can help, thanks in advance, kind regards
Brian
I am trying to retrieve a field from a custom taxonomy so that each post will have a featured image however, i cannot seem to get the field when using the field name and ID. For example,
`foreach ($terms as $term) {
echo $term_id;
echo ‘<li><a href=”‘.get_term_link($term).'”>’.$term->name.'</a></li>’;
echo get_field(‘workspace_featured_image’, “workspace_category_12”);
echo get_field(‘workspace_featured_image’, $term->taxonomy . ‘_’ . $term->term_taxonomy_id);
echo $term->taxonomy . ‘_’ . $term->term_taxonomy_id;
}`
When i run the bottom line it displays “workspace_category_number” which i believe is correct however, it is still not displaying when i use it with get_field().
Any help would be much appreciated.
Hello
I am running a website that allows race organizers to register their own race. The final goal is to propose runners to have a public website with a maximum of the races organized in France.
I have the Elementor Pro version and I also use ACF Frontend.
I propose a form to my logged-in users (race organizers) to allow them to submit their races characteristics. After submit, their race is published as a custom post type.
I dont have any issue with the form, i can configure it as I want and it is displayed as I want on a single page. All the ACF fields work nice.
My problem is with the CPT template. I can select several ACF field types with the Elementor editor (number, text..) but I can’t select taxonomy acf fields. They are not displayed in the dropdown menu. I use text editor widget/dynamic tag.
I am a newbie and i am not able to write a line of code.
Would you have a solution for me ?
Thanks.
Fabien
PS : sorry for my very poor english 😉
This is probably so simple for you all…
I have a custom post type called Job Updates (slug is job_updates)
It has 3 fields…
Job – a taxonomy
Date – date picker
Update – WYSIWYG
I would like the title of the post to auto generate based on the Job + Date
So if the job is Sherman Water Damage, it would be Sherman Water Damage 6-1-2022
I’ve searched the forum and tried several different functions in the Snippets app, while swapping out their variables for mine, but none seem to work. I don’t know php, so that might be part of it.
Hello all,
I posted this as a reply the other day here but decided a new thread is better.
My site uses the category taxonomy and posts to create a pretty standard hierarchy. One ACF field – a select probably is best – needs to have all the services to choose from – but – some are posts, others are categories.
So, I need this field to be a combination of those two fields, and in alphabetical order.
It seems that the Post Object for the posts and Taxonomy for the categories are the right choices, now I just need to merge them into one select. (This field will be on the options page in case that comes up. The data will be used on many different posts, and archive pages, that’s why it’s in my ACF Options page.)
I am trying the code John shared in that other thread:
$all = array_merge(
get_field(‘relationship_1’, false, false),
get_field(‘relationship_2’, false, false));
$args = array(
‘post_type’ => ‘speakers’,
‘posts_per_page’ => -1,
‘post__in’ => $all,
‘orderby’ => ‘title’
)
$speakers = new WP_Query($args);
// post loop
But, trying I’m unsure how to go from
$speakers = new WP_Query($args);
to the new field of merged fields. Do i instead assign the merged array $args into a new ACF select field? I probably create that field, and assign the array to it?
I think I need one of these but not totally sure:
add_action('acf/render_field/name=merged_field',
or
add_action('acf/save_post'
Thanks!
Ben
I want to offer content authors the ability to select Tags that I will show in the page.
I have a layout that has a field called “resources_carousel_topic_filter_list”. The field type is “Taxonomy Terms” and I have the Allow Taxonomy to only allow “Tags” as a horizontal row of checkboxes.
When editing the page, it looks as expected. I can select several tags.
However, I’m having trouble displaying these selected tags. I can see that ‘resources_carousel_topic_filter_list’ “has rows”, but I cannot get the selected tags.
while ( have_rows( 'resources_carousel_topic_filter_list' ) ) : the_row();
// i can get here if I put a breakpoint
endwhile;
get_field( 'resources_carousel_topic_filter_list' )
returns null as does
get_sub_field( 'resources_carousel_topic_filter_list' )
I am trying to build a Product filter with ACF, i have created a custom post type with the taxonomy filter. In this taxonomy I am using a repeated Field with text input to add select values to the filter.
For the Product pages I am trying to set the filter over a repeated field withe the taxonomy slection and add the previous added values as an Select Field.
Is there any way I can add the Values of to the taxonomy to the select Field and keep them stored without loosing them after I reload the page?
Hello.
I am building some front-end forms to create posts and add categories to specific custom taxonomies and I would like to be able to pass an ACF text field to create the category name and slug.
I’ve been successful in doing so with a post but not so much with a new category.
I have a custom post type called contacts
and I use the first and last name to update the title of the post with this:
add_action('acf/save_post', 'my_save_post', 20);
function my_save_post($post_id){
if( get_post_type($post_id) == 'contacts' ) {
// Get the data from a field
if( have_rows('contact_details') ):
while( have_rows('contact_details') ): the_row();
$first_name = get_sub_field('first_name', $post_id);
$last_name = get_sub_field('last_name', $post_id);
$title = $last_name . ', ' . $first_name;
$slug = $last_name . '-' . $first_name;
endwhile;
endif;
// Set the post data
$postdata = array(
'ID' => $post_id,
'post_title' => $title,
'post_type' => 'contacts',
'post_name' => $slug
);
// Remove the hook to avoid infinite loop. Please make sure that it has
// the same priority (20)
remove_action('acf/save_post', 'my_save_post', 20);
// Update the post
wp_update_post( $postdata );
// Add the hook back
add_action('acf/save_post', 'my_save_post', 20);
}
}
I want to do the same for a custom taxonomy within that post type called dealership
and instead have a simple acf text field dealership_name
pass that data to create the title and slug.
This is what I am trying to work with to make that happen but have a hit a wall.
add_action('acf/save_post', 'save_dealership_name', 20);
function save_dealership_name($post_id){
if( get_post_type($post_id) == 'contacts' ) {
$dealership_name = get_field('dealership_name', $post_id);
$last_name = get_sub_field('last_name', $post_id);
$title = $dealership_name;
$slug = $dealership_name;
endif;
// Set the post data
$postdata = array(
'ID' => $post_id,
'post_type' => 'contacts',
'term_name' => $title,
'term_slug' => $title
);
remove_action('acf/save_post', 'save_dealership_name', 20);
// Update the post
wp_update_post( $postdata );
// Add the hook back
add_action('acf/save_post', 'save_dealership_name', 20);
}
}
Any help would be greatly appreciated!
Hi all,
I have site with existing custom taxonomies and custom product fields. Now that I have ACF Pro, I would like ACF to “take over” control of those fields.
Is it possible?
Thanks,
Rudolf
Hello
hope somebody has an idea how to solve this:
I have CPTs like ‘case studies’ as well as ‘clients’ – the ‘client’ CPT has a taxonomy called ‘industry’.
the custom fields for the ‘case studies’ show a field ‘client’ which gets populated by the CPT client – what I like to have as well though is when I add/edit a case study and select a client I’d like to have a field that would show me the ‘industries’ attached to that specific client and then in my ‘case study’ template I’d like to show the client name as well as the industry attached to that client.
is that even possible – hope somebody can get me going.
Thank you in advance for your help.
I’m working on creating bidirectional term relationship fields. There’s a taxonomy multi-select field called related_terms, and when a term is saved with some relationships selected, I want to update those terms’ related_terms fields to include the saved term’s ID. I’m using update_term_meta() to save the related_terms array.
I have the related term ID array saving correctly to the database; it’s serialized just like terms selected through the interface. But when I refresh the edit term screen for the related term, Select2 isn’t recognizing the selected options. They’re selected correctly in the hidden field, and I can see them flash by in the form before Select2 loads, but then the field appears empty.
Have I missed something involving caching, or do I need to reinitialize Select2…?
Hi!
I have been using your great plug-in for some time now and just learnt about using the backend filters for queries and results (taxonomies and relationships) these last weeks.
Most of my taxonomie fields use the select or multiselect type. So I use the acf/fields/taxonomy/wp_list_categories filter to filter the query. That works fine.
What I would like to know is whether it is possible to format the result (as it is with the taxonomy query/result filters)? I would like to add some field content after each name of the taxonomy terms listed.
I searched the forums but couldn’t find an answer. If I missed it, please just point me at the right thread.
Regards,
aki.
I need to hide a div inside custom posts in a given category. I created an ACF True/False field and applied it to the category taxonomy for this post type. But this True/false should work on internal records that refer to the selected category to which ACF True/false is applied.
I tried something like this, but it didn’t work for me
<?php
$category = get_the_terms($id, 'product_cat');
$cater = $category[0]->term_id;
$taxonomy = 'product_cat';
?>
<?php if ( 'yes' == get_field( 'disable_finger', $taxonomy . '_' . $cater )): ?>
<?php echo 'none';?>
<?php else: ?>
<div class="finger-size-wrap">
<select class="finger-size">
<option value="" selected="selected">Select finger size</option>
<?php for($i=3; $i<=10; $i=$i+0.5){
echo '<option value="'.$i.'">'.$i.'</option>';
}?>
</select>
</div>
<?php endif; ?>
SCREENS :
https://prnt.sc/5AE-OO9UOWWw
https://prnt.sc/iqmDFypaZAAm
I’m trying to create a simple post query where the categories are an array. The return type is Term ID
Here is my code so far…
$topics = get_field('blog_post_categories');
if ($topics) {
if (!is_array($topics)) {
$topics = array($topics);
}
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'order' => 'DESC',
'cats' => $topics
);
$query = new WP_Query( $args );
any help would be greatly appreciated