ACF Relationship field in discourse_publish_format_html

For anyone who wants to expand an ACF relationship field, here’s what finally worked when the CPT I’m sending to Discourse is called memes which includes a relationship field (as object) called meme_person which links to another CPT called people

function rs_custom_publish_format_html( $output, $post_id ) {

	$post = get_post( $post_id );
	$type = get_post_type($post_id);
	
	// if featured image is present, use it
	if ( has_post_thumbnail( $post_id ) ) {
		$image = "{thumbnail}<br><br>";
	} else {
		$image = "";
	}

    // if post is a meme, get the custom field information
    if ( 'memes' === $post->post_type) {
    	$comment = get_post_meta($post->ID, 'comment', true);
		$peopleout = ' ';

		$persons = get_post_meta($post->ID, 'meme_person', true);
		if( $persons ):
			foreach( $persons as $person ):
		        $title = get_the_title($person);
				$peopleout .= $title . ' ' ;
			endforeach;
		endif; ?>

        <?php ob_start(); ?>
  
        <small>Originally published at: {blogurl}</small><br><br>
        <?php echo $image ?>
        <?php echo $comment ?><br>
        <?php echo $peopleout ?>

        {excerpt}
	  
        <?php 
        $output = ob_get_clean();
        
        return $output;
    }
  
      
    // else return
    ob_start();
    the_permalink( $post_id );
	$output = ob_get_clean();
	return $output;
    
}
add_filter( 'discourse_publish_format_html', 'rs_custom_publish_format_html', 10, 2  );

3 Likes