I guess I need to use a filter. I modified the function to the following (so $field holds that array I was talking about in the initial post) and added the filter but still no luck… Any ideas? I really appreciate your help!
function get_waiting_lists( $field ) {
$field = array();
// Query Waiting Lists Products
$args = array(
'post_type' => 'memberpressproduct',
'orderby' => 'name',
'order' => 'ASC',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'topics',
'field' => 'id',
'terms' => '22',
'operator' => 'IN'
),
)
);
$lists_array = get_posts( $args );
foreach ( $lists_array as $list ) {
$field[$list->ID] = $list->post_title;
}
wp_reset_postdata();
return $field;
}
add_filter('acf/load_field/name=select_waiting_list', 'get_waiting_lists');
rlocke, were you able to sort this out? I’m having exactly the same issue – I’ve even changed my custom field to be a select instead of the original taxonomy I was using, but still nothing is returned. When I had it set as taxonomy, the ID didn’t return anything either. If I comment out the meta_query array, the query returns posts. I’ve checked that all my names are correct, correct spelling, nothing is doing the trick. đ Any ideas?
// i've got the function code here as in example, only using 'projects_%_type'
$args = array(
'numberposts' => -1,
'post_type' => 'artist',
'meta_query' => array(
array(
'key' => 'projects_%_type',
'value' => 'lifestyle'
)
)
);
Excellent, it works. I guess I couldn’t figure it out because the rule field was just called “Term” and not something like “Taxonomy term”.
Thanks for the help, I look forward to using it to making the site even more awesome đ
Hi @psejersen
ACF can be added to a taxonomy term edit page. Just select the location rule of ‘Taxonomy term’ nad then select which taxonomy you wish for the field group to show on (product_cat).
Next, you will need to read this article to load the data into your template:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
Thanks
E
I have Unchecked option “Load & Save Terms to Post – Load value based on the post’s terms and update the post’s terms on save” in all of my taxonomy fields.
Is it that option? (to save/load to database).
I tested github version today and I can’t get it working. After replacing files ACF stopped working. In post I have just standard list of “own/meta fields’ with name/value.
If I go to ACF menu I have a list of groups of fields. Every group is empty (only input field with name) with white page under.
I tried replace files without core folder and acf.php. ACF works but admin-ajax is still called and it shows standard tinymce field above my table after first click on checkbox.
Additional info about my installation:
I’m integrating ACF plugin (and all ACF addons) into my template with require_once for example: require_once( dirname (__FILE__) . ‘/advanced-custom-fields/acf.php’ );
This helps me to integrate ACF like ‘ACF light’ version.
User don’t have plugin on plugins list. I can hide ACF menu by commenting line in acf.php: add_action(‘admin_menu’, array($this,’admin_menu’));
I can easly add more fields/change them without second installation for ACF GUI. I can just show ACF menu, done my job and hide it again.
Maybe this way of integrating ACF generates my problems with new version?
I will create new wordpress installation from scratch with normal installation of ACF plugins and I will test it again (but it takes me a while).
Hi @wietseneven
This is possible, but will not be an easy task.
Creating your own field type is quite easy. Here is a link to get you started:
http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/
What you need to do is either create a new field type which has 2 select fields, or just use 2 normal select fields to hold the data.
You can set the default choices to nothing which will give you blank select fields to work with.
Then, you can use jQuery to populate the select fields on load and when a change is detected on the select?
Does that help?
Hi @cashless
Modifying the core WP is not a smart move as it will be overridden by an update.
You should read the docs about using a custom Walker class to output the data you want.
As for actually getting ACF data for a taxonomy term, this is well documented. Please read the docs.
Thanks
E
Hi @DawidS
The AJAX call is due to the taxonomy field effecting which field groups to show / hide.
The taxonomy field contains an option to ‘save / load’ to database. If this option is NOT selected, the AJAX should not fire.
If the AJAX is firing, you are experiencing a current bug which is now FIXED in the latest ACF on github. Perhaps you could download and test it out?
Thanks
E
Hi @elliot,
My issue was that I wanted to add a second description field in my category pages on Woocommerce (with a Wysiwyg editor). The field was correctly displayed in the back-office, however in the front-office it didn’t work with the following code : <?php the_field(‘description_categorie_2’); ?>
And your code in the section “Finding the term related to the current post” (here http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/) didn’t work either.
But ayottepl gave me a clever tip to resolve it
Have a great day !
Having the same issue too.
We have set up various custom taxonomies for which we are planning to use the ACF interface to interact with, and not the native metaboxes that appear in the sidebar of the edit screen which will become redundant for our purposes.
Yes, we can hide these using the screen options panel but this is not ideal because clients can find this and switch them on, therefore causing potential headaches all round!
It would be such a great feature to be able to remove these from the ‘options’ panel when creating a field group in ACF.
I guess it’s a simple case of ACF being able to read the custom taxonomies we’ve set up for our custom post type, or depending on whatever location rule has been set, and then showing them with checkboxes in the ‘Hide On Screen’ option panel?
How to use php code to display the custom field for all category ?
The code :
<?php the_field(‘field_name’, ‘category_7’); ?>
how to make php code ‘category_7’ as taxonomy_name and taxonomy_id generate for all category ?
Hi Kyle,
Glad that helped! Makes sense with having “Load value based on the postâs terms and update the postâs terms on saveâ selectedâŠ
Have a good one.
Jeff
Bonjour elsappy,
Pour ĂȘtre capable d’afficher ça dans la page archives, tu dois avoir le ID du terme utilisĂ© pour cette archive.
Pour ma part j’ai utilisĂ© une fonction php afin de sortir le ID qui apparait dans une des classes du body… c’est pas trĂšs propre mais Ă ce moment lĂ au moins ça fonctionnait đ
Tu peux commencer en essayant avec un ID hardcodĂ© peut-ĂȘtre?
<?php the_field(âdescription_categorie_2âČ, â product_cat_19âČ); ?>
admettons. Je mets 19 Ă titre d’exemple mais tu vas retrouver cette classe sur ton champ body avec le bon id de page Ă la place. Par contre, sur ton champ body, le id va ĂȘtre reliĂ© Ă “term-” mais tu te dois d’utiliser product_cat_ pour les champs acf!
Ensuite, pour le faire dynamique, Elliot a publiĂ© un lien utile qui pourrait fonctionner (je ne l’ai pas testĂ©) : http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
En utilisant ce code suivant :
<?php
global $post;
// load all 'category' terms for the post
$terms = get_the_terms($post->ID, 'category');
// we will use the first term to load ACF data from
if( !empty($terms) )
{
$term = array_pop($terms);
$custom_field = get_field('category_image', 'category_' . $term->term_id );
//ici je remplacerais get_field('category_image', 'category_' . $term->term_id
//par get_field('description_categorie_2', 'product_cat_' . $term->term_id
// do something with $custom_field
}
?>
Tu pourrais obtenir le ID de catégorie que tu as besoin.
En gros, tu as obligatoirement besoin du 2e paramĂȘtre dans ton “the_field” qui se trouve Ă pointer la bonne catĂ©gorie đ
Bonne chance! N’hĂ©site pas si ça ne fonctionne pas, il y a toujours moyen de s’entraider đ
Hi @jeffvls-
This worked great, but only after I had selected “Load value based on the post’s terms and update the post’s terms on save.” I had already set it to grab the term object.
This really is such a blessing. Thanks for your wonderful help. Much appreciation is coming your way!
~Kyle~
Hi @slash_1968
I don’t understand your last comment. Can you please provide a clear and easy to understand question?
Thanks
E
@elliot Awesome. Thanks!!
Also, I have to say that I love this plugin, it makes WordPress SO. MUCH. BETTER.
Thanks again for all your work!
Hi @elliot,
sorry for the confusion.. i was trying to loop a post by terms under taxonomy.
Post type: Video
taxonomy: Topics
terms under topics:
– Videos
* Video type 1 (sub)
* Video type 1 (sub)
* Video type 1 (sub)
* Video type 1 (sub)
Hi @slash_1968
Just to clarify. Your question is how to get your WP_Query behaving correctly?
Lets first start by debugging the code. Perhaps you could print out the $args array. What does it look like? Does it look correct?
Then, print out the $my_query object. You will see a section of the object contains the actual SQL which is run. Does this look correct?
Please research up on the WP_Query object before posting back if you don’t understand some of the above.
Thanks
E
Hi @socki03
Yes
Hi @BenM
Currently, ACF only shows / uses heirachial taxonomies in the location field list.
I will add in a filter to enable tags as well, but this will be in a future release
Thanks
E
hierarchy correction :
– Topic
* Type a
* Type b
* Type c
* Type d
The field[‘name’] didn’t work for me. I ended up with
[name] => fields[field_5266beccd0583][]
which wasn’t exactly what I was looking for.
I ended up doing a string position find (strpos) on the $field[‘id’] for the name and I came up with the answer.
I hope this helps!
I updated taxonomy.php from the github version after finding out that 4.2.2 doesn’t include the $args array & application of filters. Will this be released in the next update? I’m just curious to make sure that this still works after the next ( or future ) updates. Thanks!
Hi @lennarto
It is always important to read the docs. In particular, the tutorial which covers how to load data from a taxonomy term:
You have used an incorrect $post_id parameter, that is what the problem is:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
Thanks
E
It turns out it was an issue with WooCommerce’s function returning the correct taxonomy id. I appreciate the help and sorry for the false alarm.
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.