Support

Account

Home Forums ACF PRO Save and show taxonomy name instead of ID

Solving

Save and show taxonomy name instead of ID

  • Hi there,

    I have some struggles with a custom Taxonomy field (coach_thema) with checkboxes. I added this field to a custom post. But when i try to get the data out of this fields, i only got to see the ID’s. I have tried a lot of things I found online, but could not find any solution. Also changing the return value doesn’t work. When i try this, it seems the whole script (of the coaches-content-page.php screenshot) crashes.

    I also use a filter plugin (filter everything), which will filter on the ‘coach_thema’ field. Also here only the ID will show up. It seems the field name is not saved, or something like that.

    Is there any fix for this?

    Here you can find some screenshots of the situation: https://postimg.cc/gallery/DSqM6tj

    I’m working with the latest version of ACF and WordPress.
    Hope there is a solution.

    With kinds regards,
    Kasper

  • You have the field set to return term IDs, if you want term objects then you need to change that.

    If the field is still returning IDs or it crashes then you have an issue somewhere else.

    Looking at your code, you are trying to do_shortcode() on the returned value. This means that you are trying to call this on a term ID, which will have no affect, or you are trying to call this on a term object, which will crash the site because do_shortcode() expects a string to be passed.

    What is it that you think you want to do when you call do_shortcode()?

  • The do_shortcode() comes out of something else, and it works for the other fields. But, i have got the field which gave the problem also fixed.

    The solution was this:

    $terms_coach_thema = get_field('coach_thema');
    if( $terms_coach_thema ): 
    	foreach( $terms_coach_thema as $term_coach_thema ): 
    		echo '<li class="werkgebied-item">';
    		echo esc_html( $term_coach_thema->name ); 
    		echo '</li>';
    	endforeach;
    endif;

    So this topic can be closed.

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

You must be logged in to reply to this topic.