I have Post Object field set up for pages. What I want to do is to output title of the posts associated with the page as a class of the div surrounding the page listing. But, the code inside the foreach loop is not being executed. I've tried with setup_postdata($post) and without, per ACF documentation, the result is always the same.
Here is the code:
function pages() {
$args = array(
'post_type' => 'page'
);
$pages = get_posts($args);
foreach ($pages as $page) {?>
<div class=" <?php
$ancestors = get_field('ancestor');
foreach ($ancestors as $ancestor) {
$class_ancestor_raw = get_the_title($ancestor->ID);
$class_ancestor_temp = explode(' ', $class_ancestor_raw);
$class_ancestor_str = implode('-', $class_ancestor_temp);
$class_ancestor = strtolower($class_ancestor_str);
echo $class_ancestor;
}
?>">
<?php echo $page->post_title; ?>
</div>
?>
<?php } ?>
$ancestors = get_field('ancestor', $page->ID);