-1

I'm using the Advanced Custom Fields plugin to place a taxonomy checkbox on certain pages.

This checkbox will filter the data that is pulled through etc on that page.

Using the example found on the ACF website (which aims at using the term object output) -

<?php 

$terms = get_field('taxonomy_field_name');

if( $terms ): ?>

<ul>

<?php foreach( $terms as $term ): ?>

    <h2><?php echo $term->name; ?></h2>
    <p><?php echo $term->description; ?></p>


<?php endforeach; ?>

</ul>

<?php endif; ?>

I can't seem to get any data to come through and when i var dump the variable, all i am left with is NULL. This code example above has been placed in the pages normal loop etc. If i change the output to show the ID however, i can see the category ID for each of the selected checkboxes.

Is there any reason why the object term would be coming up as a null array instead of showing me the slug names etc?

Many thanks

closed as off-topic by Pieter Goosen, cybmeta, birgire, Johannes Pille, Mark Kaplun Nov 28 '14 at 18:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

if I recall correctly, get_field() simply returns the value of the field, not the actual term object. try using this with get_term() (or get_term_by() depending on your needs/preference).

  • Hey, Thanks for the reply. I've done a little more testing since and it seems to work fine on an instant WP twentytweleve theme. I guess i must be doing something different in the theme. Thanks for the advice though. If i struggle to find the link i may use the ID and the get_term function for the time being. – user2391468 Nov 25 '14 at 18:45
1

Many ACF fields give you an option of what sort of data you want returned from the field. The default for the taxonomy field is Term ID, while the example code you have is for field set to return Term Object. You can change this setting under the field group in the Custom Fields admin menu page.

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.