2013-10-17 204 views
0

我在管理區域中的內容類型「團隊」中創建了一個meta_box,允許用戶選中任何要與他們關聯的標題旁邊的框創建。標題正在循環播放,它們來自不同的內容類型。將多個帖子與Wordpress中的一個帖子相關聯

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; 
    ) 
), 

這是實現這一目標的唯一途徑?

回答

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 
); 
相關問題