Support

Account

Home Forums ACF PRO Values from Taxonomy do not displayed

Solving

Values from Taxonomy do not displayed

  • Hello,

    I created an ACF taxonomy field with following settings:
    field type: https://www.advancedcustomfields.com/resources/taxonomy/
    field name: ti_tag_test
    taxonomy: post_tag
    appearance: checkbox

    To limit the displayed tags, I used following query filter:
    https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-wp_list_categories/

    function my_taxonomy_wp_list_categories( $args, $field ) {
        // modify args
        $args['orderby'] = 'count';
        $args['order'] = 'ASC';
        $args['include'] = '589,186,585,591'; // list of terms to include
        // return
        return $args;
    }
    add_filter('acf/fields/taxonomy/wp_list_categories/name=ti_tag_test', 'my_taxonomy_wp_list_categories', 10, 2);

    That works so far. Now displaying it on the frontend is where the trouble starts. I tried following code:

    <p>Hier sollten die Tags stehen:
      <?php 
      $terms = get_field('ti_tag_test');
      if( $terms ): ?>
      	<?php foreach( $terms as $term ): ?>
      		<a href="<?php echo get_term_link( $term ); ?>"><?php echo $term->name; ?></a>
      	<?php endforeach; ?>
      <?php endif; ?>
    </p>

    But for reasons unknown to me, nothing shows up.

    Thanks.

  • What show if you add some output before your loop?

    
    $terms = get_field('ti_tag_test');
    echo '<pre>'; var_dump($terms); echo '</pre>';
    

    anything?

  • Yes, output is simply:
    bool(false)

    Not sure what to do with that though. Some boxes in the acf field are certainly checked.

    Btw, regardless of this problem, you already deserved your coffee. Any way to send you the financial means for that? 😉

  • It it’s returning false that means that ACF is not finding a value for the field.

    There could be several reason for this.

    The first is that ACF does not know the post ID to get the value from. That depends on where your code is located. Is it in “The Loop”? Will need more context. What template file is this in. Where in the template does it appear?

  • Then I think it’s the missing post ID.

    The query filter/function is located in my child theme’s functions.php.

    The code snippet is inserted directly into the post via shortcode by a plugin that enables php code through a shortcode. It’s not in a template file.

  • The filter you added should not be an issue.

    But if the shortcode does not supply the correct post ID then you will need to provide that.

    You can try

    
    $terms = get_field('ti_tag_test', get_the_ID());
    

    But I can’t guarantee that will work, it really depends on how the shortcode plugin/function works.

  • Sadly, your code snippet doesn’t work.

    Btw, it’s this plugin: https://wordpress.org/plugins/insert-php-code-snippet/
    But I don’t expect anything in this direction. Maybe I will try to integrate the code directly into the theme.

    And I really need to buy you a coffee. Any chance?

  • I’m pretty sure that the issue is that you need to supply the post ID. I think this is a question for the other plugin, how to get and show the current post ID where the sortcode is inserted.

    As far as the coffee, I appreciate the offer, but I’m good, thanks anyway.

  • You can also try

    
    $queried_object = get_queried_object();
    $terms = get_field('ti_tag_test', $queried_object->ID);
    
  • Sadly, no luck again.

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

You must be logged in to reply to this topic.