ACF のリレーションシップフィールドを拡張したい方のために、私が送信している CPT が memes で、そこには people という別の CPT へリンクする(オブジェクト形式の)リレーションシップフィールド meme_person が含まれている場合に、最終的に機能した方法を共有します。
function rs_custom_publish_format_html( $output, $post_id ) {
$post = get_post( $post_id );
$type = get_post_type($post_id);
// 投稿画像がある場合はそれを使用
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 );