Wordpress ACF如何在Admin中为自定义关系字段显示帖子标题以外的内容



我有自定义的帖子类型,对于这些类型,有一个"title"字段实际上没有意义,所以帖子类型没有。

问题是,当您在关系中使用帖子类型时,用于选择要关联的帖子的用户界面希望显示标题。

在您选择帖子的框中(单击它们,它们就会移动到右侧窗格(,是否可以显示除"标题"之外的字段?

这是可行的。我会使用acf插件'acf/fields/relationship/result/name=related_posts'提供的过滤器挂钩。看看下面的代码:

add_filter( 'acf/fields/relationship/result/name=related_posts', 'my_custom_title', 10, 2 );
function my_custom_title( $title, $acf_array ) {
// You could remove the $title altogether or you could add something meaningful to it such as time stamp or anything that would make sense!
return $title . "Adding somthing meaningful to the title!";
}

最新更新