2013-01-24 22 views
0

所以我有一個自定義元框,我試圖通過動態內容。我需要能夠通過一些帖子循環拉取該信息,然後將其存儲到數組中,然後將這些數組放入下面顯示的選項數組中。在Wordpress中存儲數組中的動態數組

這是我在迄今爲止在那裏..

array(
     'label' => 'Overseeing Pastor', 
     'id' => $prefix.'pastor', 
     'type' => 'select', 
     'options' => array (
      $args = array('post_type' => 'employee', 'position' => 'pastor'); 
      $pastorList = new WP_Query($args); while ($pastorList->have_posts()) : $pastorList->the_post(); 
       array (
        'label' => get_the_title(), 
        'value' => get_the_ID() 
       ), 
      endwhile; wp_reset_postdata(); 
     ) 
), 

選項部分是什麼,我需要幫助。我明白這顯然是行不通的。有沒有辦法將數組存儲爲其他地方的varibale,然後在options數組中調用它?感謝任何幫助,我在這一張上撕掉了我的頭髮。

回答

1

是這樣的嗎?

$options = array(); 
$pastors = get_posts($args); 

foreach ($pastors as $post) { 
    $options[] = array(
     'label' => $post->post_title, 
     'value' => $post->ID, 
    ); 
} 

還是這樣?

foreach ($pastors as $post) { 
    $options[$post->post_title] = $post->ID; 
} 
+0

感謝這工作完美的我需要什麼。感謝你的幫助。 – souporserious