Home Forums General Issues Field group at taxonomy does not work


Field group at taxonomy does not work

  • Hello,

    I’ve been looking for the solution to this problem for hours … unfortunately I have not found.

    After creating a “custom post type” (with taxonomy) – I created a group of fields to the taxonomy (for this taxonomy only). Unfortunately, I can not somehow recover the value of the custom field of taxonomy. Seriously, I’m in it for at least 5 hours :O

    Someone could help me please?

    Custom post type: audiobag
    Name of taxonomy: audiocategorias
    Custom field on taxonomy: ab_rolp

  • Hi mdetoni. Not totally sure I understand – are the custom fields bound directly to the taxonomy itself?

  • Im having the same issue I can not get the field value to display on Custom Taxonomy Term Page.

    Custom post type: stations
    Name of taxonomy: radioroom
    Custom field on taxonomy: style_id

    I even submitted a ticket about this and willing to pay to have it figured out.

  • Hello guys,

    emcniece – I’ll try to write a little better. My apologies for my english.

    1 – I created a ‘custom post type’ called “audiobag”
    2 – I created a taxonomy called “audiocategorias”, which is attached to custom post, “audiobag”
    3 – Using the ACF plugin, I created a ‘custom form’, with some fields
    4 – In the custom form I created (in step 3) – I set a rule to display form: Taxonomy Term equals ‘audiocategorias’

    My goal: When I show audiobag-single, also display the data defined in custom form for taxonomy.

    After two days I could not make it work. I figured it might be some incompatibility with my theme, or am doing absolutely everything wrong. So I developed a plugin that creates a json for each taxonomy – but do not think an elegant solution, my intention would be to use the ACF to all.

    Thanks for your answers and help.

  • Just wanted to confirm that I’m having the same issue.

    I was trying to add a field type taxonomy to a “show if field group” is taxonomy term, and the field shows up on the taxonomy page but couldn’t get it to show up in my theme. Hope that make sense.

  • Ok, I’ve done a bit of testing and I agree that something is not working as expected… until I figured out how to get taxonomy fields. I’ll try and lay this out so that you guys can tell me if I’m doing the right thing!

    Steps to reproduce:

    1. Add a new Field Group: /wp-admin/post-new.php?post_type=acf
    2. Add a new field to this group
    3. Set the Location Rules: Show field group if Taxonomy Term is equal to [taxonomy], Save field group
    4. Add a new taxonomy term with the custom field: /wp-admin/edit-tags.php?taxonomy=[taxonomy]
    5. Attempt to retrieve field in theme with get_field()

    I was unable to get the field data properly until realizing that I wasn’t calling the taxonomy field properly.

    So getting the field data looks like this (using @mdetoni’s taxonomy):

    $terms = get_terms( 'audiocategorias', array( 'hide_empty'=>false ) );
    foreach($terms as $term){
    	$field = get_field('ab_rolp', $term->taxonomy.'_'.$term->term_id)
    	echo '<pre>field: '.print_r( $field, true).'</pre>';

    To get taxonomy fields, the post ID variable must start with taxonomyname_, so in this case audiocategorias, or in the example we pull it directly from the taxonomy term itself: $term->taxonomy.'_'.

    Does this help anyone or am I heading in the wrong direction?

    Edit: @drift2’s example

    $terms = get_terms( 'radioroom', array( 'hide_empty'=>false ) );
    foreach($terms as $term){
    	$field = get_field('style_id', $term->taxonomy.'_'.$term->term_id)
    	echo '<pre>field: '.print_r( $field, true).'</pre>';

    Note that in these examples we are using 'hide_empty'=>false in order to force the retrieval of terms. This is required for a term to show up in our list if there aren’t any posts with this term selected.

  • Thanks for the reply.

    I tried the docs ( examples but couldn’t get it to work. I’ll work through it again when I get a chance. I tried it on a client’s site and ended up scrapping it because it wouldn’t work.

  • @madebytincans do you remember where you were making the get_field() calls? I’ve had a few issues recently with using ACF fields before the global query object was initialized.

  • Hi emcniece thanks for the code however its still does not provide me with the results I am looking for. Im trying to get the field of the taxonomy term page. Like if I wanted to put an image on each category page. Here is the link to the existing site and as of right now its displaying the code you provided.

    To elaborate more on the over all goal I want to be able to have a custom slider, and custom css applied to on all pages, taxonomy term pages, and even post.

  • @drift2 The code provided will loop through all available terms within that taxonomy, so we have to adjust it if we’re focusing on a single term.

    $current_term = get_taxonomy( get_query_var( 'taxonomy' ) );
    $field = get_field('style_id', $current_term->taxonomy.'_'.$current_term->term_id);
    echo '<pre>field: '.print_r( $field, true).'</pre>';

    Any luck?

    Edit: sit tight, this code will fail
    UPDATE: Code for single term:

    $term = get_term_by( 'slug', $wp_query->query_vars['term'], $wp_query->query_vars['taxonomy']);
    $field = get_field('style_id', $term->taxonomy.'_'.$term->term_id);
    echo '<pre>field: '.print_r( $field, true).'</pre>';
  • @emcniece Thanks for the help the code did not work for me however your direction and the info on lead me to the code that did work.

    $queried_object = get_queried_object(); 
    $field = get_field('style_id', $queried_object);
    echo '<pre>field: '.print_r( $field, true).'</pre>';
  • Hello again guys,

    I tested the solution provided by @emcniece. And worked perfectly for me.

    I pasted the code at my php file and everything works fine now.

    Really really appreciate the help.

  • Sorry, I don’t recall. I thought I could get something going quickly with ACF but had to scrap it all because I needed a solution that day.

    I was trying to do exactly what the screenshots on this page ( except on a taxonomy.

    Perhaps I misunderstood or maybe the docs for taxonomy field can be updated.

    Thanks guys

    Unrelated: I just noticed that you can’t add a link through this editor. Weird.

  • Nice work guys! Glad we got that sorted.

    be sure to set this thread as solved if we’re good to go.

    I’ll be watching that site with interest… shoot me a PM when that goes live 😉

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

The topic ‘Field group at taxonomy does not work’ is closed to new replies.