0

我在管理区域的内容类型“团队”中创建了一个 meta_box,允许用户选中他们想要与他们正在创建的内容相关联的任何标题旁边的框。标题正在循环播放,它们来自不同的内容类型。

  array(
    'name' => __('Player List', 'theme_name'),
    'desc' => 'Select all the players that are on the team you are creating.',
    'id' => 'theme_name_players_completelist',
    'type' => 'checkbox',
    'options' => array(
        $args = array( 'post_type' => 'players');
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post();
        array('name' => __(the_title(), 'theme_name'), 'value' => 'get_the_ID()'),
      //But here is where I need to loop through and show the titles of the content type called team_members. The value could be the post ID or Title or whatever I guess.
         endwhile;
    )
  ),

这是实现这一目标的唯一方法吗?

4

1 回答 1

0

我不确定您是否可以构建这样的数组,但可以将其简化为(未经测试):

$posts = get_posts( array( 'post_type' => 'players') );
$options = array();

if( $posts ) {
    foreach( $posts as $post ) {
        $options[$post->ID] = $post->post_title;
    }
}

$the_array = array(
    'name' => __('Player List', 'theme_name'),
    'desc' => 'Select all the players that are on the team you are creating.',
    'id' => 'theme_name_players_completelist',
    'type' => 'checkbox',
    'options' => $options
  );
于 2013-10-17T02:35:59.547 回答