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; ?>