Get ACF Post Object Slugs and Echo as Class Names or Data Attribute

PHOTO EMBED

Wed Oct 20 2021 23:37:10 GMT+0000 (Coordinated Universal Time)

Saved by @markf_raindrop #php

// Setup
$post_objects = get_field('acf_post_object_field');
$slug_array = array();

// Loop
if($post_objects) {
  foreach($post_objects as $post_object):
  
  	// Get slug and place into the array
  	$slug_array[] = $post_object->post_name;
  
  endforeach;
}

// Echo
<?= implode(' ', $slug_array); ?>
content_copyCOPY

crackshack.com