The function works the way it’s supposed to, like I said, as long as there isn’t any errors. I’m not having any issues with ACF working correctly. I think you’re going down the wrong path by trying to figure out what ACF is doing.
To answer your questions, the load_value() method in each field class does what it needs to do base on the field type. The post object fields for examples returns a post ID, or an array or post IDs if something is saved or it returns flash if nothing is saved. On the other hand the taxonomy field has a lot more work to do. All of the functions in ACF are real function, they all do something.
I’m not sure what you mean by adding tracking to the ajax function. This will only run when the ajax request is made. If the function is never run then I would say that there is a JavaScript error that prevents the request from being made in the first place. This goes back to my first reply.
Have you checked for JavaScript errors? Or php errors during the AJAX request?
Ok- got it to work. I think the “taxonomy term” filter type might have gone the way of the dodo in a recent release, replaced with taxonomy = all (if you want the field for all taxonomies). When I chose this, my custom fields appeared.
Also, you can filter for the fields to only appear on certain terms with the post taxonomy = whatever category you choose.
If you are still having issues and it is not appearing, see if another field group is already targeting those taxonomies or specific categories. I’m not for sure the rules on multiple field groups to the same targeted whatever, and there could always be a bug.
But I think the above will solve what ails ye. Let me know if it doesn’t.
Okay, I understand a tad better how all of this is running, but still, I haven’t solved my issue.
According to what you said, I dug my way from the called AJAX (with action: acf/post/get_field_groups
) but again, I’m stuck in the function acf_get_value() in file “api-value.php”, where, I understand, the value are fetched for filling the field.
Several filters are applied but none return anything :
$value = acf_get_metadata( $post_id, $field['name'] );
...
$value = apply_filters( "acf/load_value", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/key={$field['key']}", $value, $post_id, $field );
(This is for a new post, for an older post, acf_get_metadata returns the values for the field already associated with the post)
I printed the output of each call, but they all come back empty.
Furthermore, the load_value() function from “class-acf-field-post_object.php” looks like this :
function load_value( $value, $post_id, $field ) {
// ACF4 null
if( $value === 'null' ) return false;
// return
return $value;
}
This function doesn’t look really useful to me… I checked on other class files, “class-acf-field-select.php” has the same function, but other files (ex “class-acf-field-taxonomy.php”) have real code for this function, so, even if I updated the plugin yesterday, I wondered if some files have been altered and not updated, or if these function are the real ones.
I also checked about select2, since you mentionned it, I found a get_ajax_query() function in “class-acf-field-post_object.php” (“This function will return an array of data formatted for use in a select2 AJAX response”) which seems to do what I want, but I put some tracker in it, and it doesn’t seem to be called, so maybe the problem is this function should be the one called, but because of some bug, it isn’t and another one is instead ?
It is possible to import into a taxonomy using names with WPAI, and it is possible to also import into ACF taxonomy fields using term names using the ACF add on. If you have the taxonomy field set to “load terms” and “save terms” then you should only need to import to the taxonomy though the standard WPAI taxonomy interface. If you are not loading and saving terms they you’ve probably got to import both with the standard taxonomy settings in WPAI AND import into the ACF field and you should be able to do this using the names and WPAI will sort it out for you.
Bit I don’t remember all the details. I’ve been where you are, I hate imports unless it is to import something that is exported from some other system. If you’re importing from data manually entered into a spreadsheet by a client then, well, this is only the beginning of what you’ll need to work out. Human entered data is never consistent enough for automated importing.
The problem is that when you export the content in the ACF field it contains a Term ID value, not the name of the term. I’m not sure what you’re using for the export, but when you import that term is probably getting a different ID value. How are you exporting? How are you setting up WPAI to import the values to the taxonomy field? Are you using the ACF add on for WPAI?
I was able to solve it, thank you one more time.
I now have to check how the code does not influence the tags. When I link it it also changes the tags in the loop. I’ll check that out.
For those who have doubts about how to proceed, follow the code below:
<?php
$posts = get_field('related_series', $taxonomy . '_' . $term_id);
if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li><?php $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $p->ID ), 'featured', false, '' );?>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?><?php echo '<img src="'.$feat_image[0].'">';?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Then just code for your needs. I’ll try to do per repeater field.
I only need to solve three issues with acf to be able to finish my project =). Man, I’ll come soon, pay for some coffee or juice for you!
Beee helping ever !!
This is a related question (tell me if I rather should open a new issue instead):
In order to add terms to a taxonomy a user must have the correct permissions to do so. In WP for categories this would be manage_categories.
I have a logged in user with the manage_categories
capability but I still do not see the ability to add new terms from the front-end. Is there any other capability that is needed as well?
This code` <?php
$posts = get_field(‘related_series’, $taxonomy . ‘_’ . $term_id);
if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href=”<?php echo get_permalink( $p->ID ); ?>”><?php echo get_the_title( $p->ID ); ?><?php the_post_thumbnail( ‘featured’ ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>`
I used the example link: https://www.advancedcustomfields.com/resources/relationship/
And I added to get the featured image from the related post. However, he repeats the same image for all posts. This is not a repeater field. I’m doing the test without the repeater field.
Hi there,
Also struggling with this one and I’m using a custom taxonomy on a custom post type. The multi-select works find on the backend when editing the custom post type, but when rendering the form on the front-end (logged in or not) then I just get an empty select.
There are no JS error and also no HTTP requests issues. All assets are loaded fine.
Any movement on this?
As it says on this page https://www.advancedcustomfields.com/resources/shortcode/
Limitations
• Only works for simple text based values
If you want to use shortcodes for other fields then you need to build your own shortcodes https://codex.wordpress.org/Shortcode_API. The Taxonomy field stores the ID value of the terms and the build in shortcode only shows the value that stored.
I probably completely overlooked it, but your syntax appears to be wrong.
You use
echo get_field('custom_category_description', 'option');
but you need to use
echo get_field('custom_category_description', {taxonomy}_{term_id});
So now I’m wondering why you get an output if this is the actual code, because your code retrieves an option field value and NOT a taxonomy description (or I’m not understanding your setup fully).
I just realised that the default taxonomy description is also a wysiwyg editor (never realised this. I never use it).
Have you tried that as well ?
Forget that last part (for now).
I just did a test. I added a wysiwyg field to my taxonomy and added my shortcode, which is [home_url].
When I var_dumped this field as follows:
var_dump(get_field('content','{taxonomy}_{term_id}')); exit;
it gives me my home_url.
If I then echo it on my page it produces the same value.
And I didn’t apply any filter or do something extra. This is straight out of the box. So my first guess now is you have something activated (like a filter or so) which stops this shortcode from outputting.
Have you tested this with all plugins deactivated and on a default WP theme ?
Hi Beee,
Here the code to retrieve the field:
<?php
if ($term = get_queried_object()) {
$taxonomy = $term->taxonomy;
if ($taxonomy == "product_cat") {
echo get_field('custom_category_description', 'option');
}
}
?>
Where should I put ‘the_content’?
Thanks,
Hi Beee,
Here my code:
/* Shortcode for additional product meta */
/* Shortcode for single product details */
function shortcode_product_title() {
global $product;
return $product->get_title();
}
add_shortcode('ouffice_product_title','shortcode_product_title');
function shortcode_product_cat() {
global $product;
$category = get_the_terms( $product->ID, 'product_cat' );
if ($category) {
return $category[0]->name;
} else {
return '<span style="color:red">[please input the category of this product]</span>';
}
}
add_shortcode('ouffice_product_cat','shortcode_product_cat');
function shortcode_product_brand() {
global $product;
//var_dump($product);
$brand = get_the_terms( $product->ID, 'product_brand' );
if ($brand) {
return $brand[0]->name;
} else {
return '<span style="color:red">[please input the brand of this product]</span>';
}
}
add_shortcode('ouffice_product_brand','shortcode_product_brand');
function shortcode_category_title() {
if ($term = get_queried_object()) {
$taxonomy = $term->taxonomy;
if ($taxonomy == "product_cat") {
return $term->name;
} else {
return 0;
}
}
}
add_shortcode('ouffice_category_title','shortcode_category_title');
I actually solved my problem with WYSIWIG ACF not showing up on taxonomy with this code – basically having to pass the taxonomy and post id in the get_field parameter. This only seems to be necessary on the WYSIWIG field, all other field display with out this.
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$post_id = $taxonomy . '_' . $term_id;
$custom_field = get_field('MY-ACF-FIELD-NAME', $post_id);
echo $custom_field;
Did you get this solved? I have a custom taxonomy with several ACF attached to it. For some reason one of the fields, a WYSIWIG never shows up using get_field, and only ever shows null if I printr it. I have deactivated all plugins but nothing I have tried makes it display.
I have copied content-product_cat.php to my theme Woocommerce folder and tried this answer
/**
* woocommerce_after_subcategory hook.
*
* @hooked woocommerce_template_loop_category_link_close - 10
*/
do_action( 'woocommerce_after_subcategory', $category ); ?>
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$thumbnail = get_field('productdesc', $queried_object);
$thumbnail = get_field('productdesc', $taxonomy . '_' . $term_id);
?>
<?php the_field( 'productdesc', $queried_object ); ?>
But it doesnt help. Any help please!
If there is an error then it has to do with something else. This is the correct way to get field values from a term. You can also supply the term object. https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
Do you have the image field set to return a URL? https://www.advancedcustomfields.com/resources/image/
This is somewhat involved, but assuming you have a player post for every player and a post for tracking the scores for each game, I would do the following:
Create a taxonomy for the games. Ex.: Summer Tournament 2018.
Create a field group with a number field for each game. So, if there are 16 games, there will be 16 boxes. Set your rules to have these appear where the Post Type is Player (or whatever your CPT is for players).
Create a repeater with two fields: a post object field (players) and a number field. This should appear in whatever post or page you are using to keep track of a given game. The post object field will link the game to the player. Set your rules to appear where Post Type is (whatever post you are tracking the scores for each game) and the Taxonomy is (whatever you call your tournament). This is where you will track the scores for each player for a given game.
Create a post for each of the summer games.
The update field function will involve:
Running a query to get the post ids for all the summer games.
An outside loop of all the summer games, and an inside loop of the repeater with the scores for each game.
Now you can grab the post id of the player and update the box corresponding to the game in the players profile.
Now you can loop through each player and show their points on a separate page.
You have to add this to your query:
So if you were trying to look for houses with the following criteria:
CPT: houses
Country: United States
City: Los Angeles
Beach: Manhattan
I don’t know what your taxonomy slugs are, but insert them own below:
$args = array(
'post_type' => 'houses',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'country',
'field' => 'name',
'terms' => 'United States',
),
array(
'taxonomy' => 'city',
'field' => 'name',
'terms' => 'Los Angeles',
),
array(
'taxonomy' => 'beach',
'field' => 'name',
'terms' => 'Manhattan',
),
),
);
Apologies, I don’t make sense to myself either!
What I have (on the backend) is a ACF Taxonomy field call “selecttaxonomy” which is a dropdown of EDD categories and I can pass this into a php that lists what products are under that category but this means changing the backend every time as you can’t get the taxonomy field to be a choosable field (dropdown, checkbox, anything) on the front end.
I then created a seperate dropdown and have tried to pass the choice into the original php code but can’t.
As for the <form> command, I got the code from the Codex & haven’t got a clue what it does!
I hope thia makes more sense this time.
OK… I finally got it. This is what the correct query should have been, combining ACF and CPT arguments:
$relatedCat = get_field('service_related_industry');
$args = array (
'posts_per_page' => 3,
'post_type' => 'case_study',
'tax_query' => array(
array(
'taxonomy' => 'cs_industry',
'terms' => $relatedCat,
'field' => 'term_id',
),
),
'tag_id' => '"'.$relatedCat.'"',
'orderby' => 'DESC',
);
Your question has made me realise that the issue is probably not with the ACF part but the Custom Post Types taxonomy I was querying.
get_field is correctly pulling the field ID. However, my $args was not querying for posts filtered by taxonomy. I’ve changed the code to:
<?php $relatedCat = get_field('service_related_industry');
$args = array (
'posts_per_page' => 3,
'post_type' => 'case_study',
'tag_id' => '"'.$relatedCat.'"',
'orderby' => 'DESC',
It’s still not working properly, but at least now it isn’t pulling all the posts (it’s pulling exactly the 3 latest, while ignoring the ‘tag_id’ filter).
You need to set the values of fields with the type of data that ACF would use. If it is a select field that can have multiple values then ACF needs an array of values, if it’s something like an image field, taxonomy, post object, relationship then ACF is expecting the ID value of the related object or an array of IDs.
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.