我有一个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 )。
发布于 2015-03-18 17:18:41
找到解决方案:
$date_array[$id] = $date;太简单了,现在感觉很傻xD
https://stackoverflow.com/questions/29101297
复制相似问题