在Wordpress中的数组中存储动态数组

时间:2013-01-24 21:42:09

标签: php arrays 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 个答案:

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