discourse_publish_format_html의 ACF Relationship 필드

ACF 관계 필드를 확장하려는 분들을 위해, Discourse로 전송하는 CPT가 memes이고, 이 CPT에 people이라는 다른 CPT를 참조하는 객체 형태의 관계 필드 meme_person이 포함된 경우, 마침 작동한 방법을 공유합니다.

function rs_custom_publish_format_html( $output, $post_id ) {

	$post = get_post( $post_id );
	$type = get_post_type($post_id);
	
	// featured image가 있으면 사용
	if ( has_post_thumbnail( $post_id ) ) {
		$image = "{thumbnail}<br><br>";
	} else {
		$image = "";
	}

    // 포스트가 meme이면 커스텀 필드 정보를 가져옴
    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;
    }
  
      
    // 아니면 반환
    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  );