Support

Account

Home Forums Front-end Issues Get Custom Taxonomy Field Value

Solved

Get Custom Taxonomy Field Value

    • MACscr

    • July 9, 2013 at 3:57 pm

    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. =/

    • Elliot

    • July 10, 2013 at 2:57 pm

    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/

    • rapidz

    • September 17, 2013 at 5:11 pm

    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.

    • rapidz

    • September 17, 2013 at 5:29 pm

    Must’ve been something with the field name. I added a new field with the name cm_id and it worked.

    • BLiN

    • December 19, 2013 at 12:27 am

    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

    • Elliot

    • December 19, 2013 at 10:02 am

    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?

    • Elliot

    • December 5, 2019 at 10:06 am

    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/

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.