使用自定义 post 类型的标题列表作为 ACF 字段的值

Use list of titles of custom post type as values for ACF field

我想在我的 Wordpress post 中添加一个 'Post Author' select 选项。我不想在 Wordpress 中创建 30 个左右不同的用户,而是想用自定义 post 类型(员工)的所有标题填充 ACF 下拉 select 字段。

我找到了用于输出自定义 post 类型标题列表的代码...

 // query for your post type
$post_type_query  = new WP_Query(  
array (  
    'post_type'      => 'your-post-type',  
    'posts_per_page' => -1  
)  
);   
// we need the array of posts
$posts_array      = $post_type_query->posts;   
// create a list with needed information
// the key equals the ID, the value is the post_title
$post_title_array = wp_list_pluck( $posts_array, 'post_title', 'ID' );

...我从一篇关于动态填充 select 框的 ACF 文章中找到了这段代码...

function acf_load_color_field_choices( $field ) {

// reset choices
$field['choices'] = array();


// get the textarea value from options page without any formatting
$choices = get_field('my_select_values', 'option', false);


// explode the value so that each line is a new array piece
$choices = explode("\n", $choices);


// remove any unwanted white space
$choices = array_map('trim', $choices);


// loop through array and add to field 'choices'
if( is_array($choices) ) {

    foreach( $choices as $choice ) {

        $field['choices'][ $choice ] = $choice;

    }

}


// return the field
return $field;

}

add_filter('acf/load_field/name=color', 'acf_load_color_field_choices');

...但是我真的不确定如何将两者拼接在一起,以便它获取我的自定义字段标题并将它们添加到 ACF 字段 selector.

我试过了,但无法显示任何结果。

有什么想法吗?

感谢 mmmm 的评论,我能够使用 ACF 中的 'Relationship' 字段类型来实现我想要的...这是我的代码供任何感兴趣的人使用

'post-author'是ACF字段的名字,这里设置的是relationship,在options中选择了自定义post类型'staff',所以我可以选择任意成员的工作人员。然后将它们输出到 post 中,带有缩略图和职位...

<?php

$posts = get_field( 'post-author' );

if ( $posts ): ?>

<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>

<div class="author">
<?php the_post_thumbnail('small'); ?>
<div class="author-text">
    <a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
    </a>
    <p>
        <?php the_field('job_title') ?>
    </p>
</div>
<div class="clearfix"></div>
</div>

<?php endforeach; ?>

<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>