将多个帖子与Wordpress中的一个帖子相关联

时间:2013-10-17 01:16:35

标签: php wordpress loops content-type

我在管理区域的内容类型“团队”中创建了一个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;
    )
  ),

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

1 个答案:

答案 0 :(得分: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
  );