对于任何想要扩展 ACF 关系字段的人,以下是最终生效的方案:我发送给 Discourse 的自定义文章类型(CPT)名为 memes,其中包含一个名为 meme_person 的关系字段(作为对象),该字段链接到另一个名为 people 的自定义文章类型。
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 = "";
}
// 如果文章类型是 memes,则获取自定义字段信息
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 );