Support

Account

Home Forums Front-end Issues ACF taxonomy in query

Solved

ACF taxonomy in query

  • This seems really easy but I’m banging my head against a wall trying to get the solution!

    I’m trying to do a WP Query that will shows posts from selected categories in the admin area.

    I followed this code to begin, with the hope of it working and then working out how to get the IDs;

    <?php 
    	$terms = get_sub_field('category');
    	if( $terms ): 
    ?>
        <ul>
        <?php foreach( $terms as $term ): ?>
            <h2>Term: <?php echo esc_html( $term->name ); ?></h2>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>

    It’s a sub_field because it’s inside flexible content.

    All I get back is “Term:”, then it’s blank….

  • Changed ACF in admin area to “Post Object” and then use;

    <?php 
    	$terms = get_sub_field('category');
    	if( $terms ): 
    ?>
        <ul>
        <?php foreach( $terms as $term ): ?>
            <h2>Term: <?php echo esc_html( $term->term_id ); ?></h2>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF taxonomy in query’ is closed to new replies.