从post id创建有序数组,从post创建自定义值


Create ordered array from post id and custom values from post

我有一个wordpress查询,它通过自定义帖子类型的帖子。我有

$args = array(
        'post_type' => 'custom_post_type',
        'posts_per_page' => '-1',
    );
$post = new WP_Query( $args );
if ($post->have_posts()){
    while ($post->have_posts()){
        $post->the_post();
        $id = get_the_ID();
        $custom = get_post_custom($id);
        $date = $custom["custom_date"][0];
    }
}

我需要创建一个数组,它将id作为相应值的键和日期,比如:

Array
(
    [123] => 2014-1-1
    [456] => 2015-2-1
    [789] => 2013-2-8
    [012] => 2011-12-12
)

我完全不擅长php数组。我试着只创建一个空数组,然后给它赋值,但什么也没发生(只是把array弄出来了)。

找到解决方案:

$date_array[$id] = $date;

这么简单,现在感觉很愚蠢xD