Home › Forums › Front-end Issues › Get Custom Taxonomy Field Value
I have a custom Taxonomy term named ‘Campus’. I then have a custom field within that term called ‘Address’. Any suggestions on how I should best return the Address when I have the value of Campus? Im hoping to avoid a dirty sql query, then having to cache it myself so that i dont have to make a special query on each page load. This taxonomy is not related to a particular post. Nor should it need to be in my opinion. I asked this question earlier this year and I never figured it out, but since you changed forums, I cant just continue my last post or go back and check it out. =/
Just to clarify, you are asking how do you load a custom field value from a taxonomy term when you know the taxonomy type and the term ID?
Please read this documentation article:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
I’m having the same issues. I’m using WooCommerce, WPML and ACF. WooCommerce creates a custom taxonomy called ‘product_cat’. The name of the field I’m trying to get is ‘Subscribe Field Name’.
I’m using the following, but it’s not returning anything:
<?php echo get_field('subscribe_field_name', 'product_cat_16');?>
It’s driving me crazy.
Must’ve been something with the field name. I added a new field with the name cm_id and it worked.
It’s driving me crazy but I totaly don’t understand how I can get value from custom filed that is custom taxonomy term (select). I read “How to get values from a taxonomy term” 10 times. I search all the forum with words taxonomy custom field. I don’t understand where I can get value of $TermID?
<p><?php the_field(‘field_name’, ‘category_7’); ?></p>
– so tell me please where are you get that “7” ?
I have custom taxonomy called ‘my_taxonomy’ (I use Custom Post Types UI plugin) and I have custom field (my_field – select from taxonomy values list) in custom post (type my_post_type). So I want to post its value in frontend?
Will be appreciate if you colud give the examples or the link to docs or at least turn me to the right way.
1) Get the taxonomy (one value – select or radiobutton) field value?
2) Get the taxonomy (few values – checkboxes) field array of values?
3) Get the repeater nested taxonomy field value?
Thanks in advance
P.S. Sory for my bad english. May be that SQL clear what I want –
SELECT name
FROM wp_terms
WHERE term_id
IN (
SELECT term_id
FROM wp_term_taxonomy
WHERE taxonomy = 'where_from'
AND term_taxonomy_id
IN (
SELECT term_taxonomy_id
FROM wp_term_relationships
WHERE object_id =418 //post_id
)
)
but instead of ” taxonomy = ‘where_from’ ” – value from unknown table that has relationship field_name — taxonomy_name
Hi @BLiN
You say that you have used a taxonomy field to select a taxonomy. Is this a single or multiple select field?
To get the selected taxonomy term, you use the get_field function like so:
$term = get_field('taxonomy_field_name')
Then,make sure you have a return format setting of ‘Object’ instead of ‘ID’.
You can then use $term to load data from the taxonomy term like so:
<?php
// load thumbnail for this taxonomy term
$thumbnail = get_field('thumbnail', $term->taxonomy . '_' . $term->term_id);
?>
Thanks
E
I think my problem is similar to what’s been going on here, but I’m still coming up blank.
I have a taxonomy field (checkbox, so multiple items can be chosen) inside a custom post type. So far so good. My query displays the selected taxonomies.
But within those custom taxonomy terms I’ve added a FontAwesome field, so each term has an icon associated with it.
What I’m trying to do is display all icons of terms selected within the custom post.
Here’s my code so far (like I said, the term name itself is displaying just fine, but I want the icon associated with that term to be displaying):
<?php $terms = get_field('tech_choices');
$cat_icon = get_field('creative_icon', $queried_object); ?>
<span>
<?php if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li><a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?></a></li>
<?php $icon = get_field('creative_icon', $term->taxonomy . '_' . $term->term_id); echo $icon; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</span>
The link above ( http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/ ) gives a 404. Based on the URL, I would really like to read that article (and I can’t find it, using Google). Any help?
Hi @zethzethdk. The article you are looking for is this one: Adding fields to a taxonomy term – https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
This worked for me to get the taxonomy terms for the current post with an ACF icon field attached:
<?php $terms = get_the_terms( get_the_ID(), 'project_services' );
$cat_icon = get_field('icon', $queried_object);
?>
<?php if( $terms ): ?>
<ul class="menu">
<?php foreach( $terms as $term ): ?>
<li>
<a href="<?php echo get_term_link( $term ); ?>">
<?php $icon = get_field('icon', $term->taxonomy . '_' . $term->term_id);?>
<img src="<?php echo $icon ?>">
<?php echo $term->name; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
The topic ‘Get Custom Taxonomy Field Value’ is closed to new replies.
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.