Support

Account

Home Forums Bug Reports get_field_objects() returning false for Taxonomy query

Helping

get_field_objects() returning false for Taxonomy query

  • Hi, love the plugin and all the great development options that it gives us!

    I’m not sure if this is a bug per se (maybe it’s a feature request) but I’m pretty sure the problem isn’t on my end. According to the docs for get_field_objects(), we should be able to pass in a taxonomy as we would other post/content types via the $post_id param:

    $post_id: Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc

    And this documentation shows how we can use the API by passing a WP $term object.

    I’m able to use functions to get single field values with this method, but I’m trying to use the get_field_objects() function to get all fields for a given taxonomy term, and this always returns false. Here’s a simplified version of what I’m trying to accomplish:

    
    <?php 
    // getting a term object
    $term_obj = get_term( 3, ‘_custom_tax_slug' ); 
    
    // this should return an array of ACF field objects, if I am understanding the docs
    $acf = get_field_objects( $term_obj ); 
    
    // this outputs bool(false) every time across all taxonomies
    var_dump($acf);
    ?>
    

    It’s possible that this just isn’t supported by the get_field_objects() function, but it seems as though it should be. If not, I can change this to a feature request but it’d be helpful to be clearer in the documentation that this isn’t possible.

    Thanks for any help, and thank you very much for such a great plugin! -Matt

  • Hi @oppodeldoc

    The get_field_objects() function would not work in this scenario since you are trying to query some term objects.

    I would recommend you make use of a for each loop to get the terms as shown below:

    <?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>
    		<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
    
    	<?php endforeach; ?>
    
    	</ul>
    
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘get_field_objects() returning false for Taxonomy query’ is closed to new replies.