0

我有三个数组获得不同的帖子类型,然后将它们合并以在 Wordpress 管理员中进行下拉。我正在尝试插入空值/中断以使下拉列表更易于阅读。

这是数组和array_merge:

// creating an array of pages

$featpages = array();
$pages = get_pages();
$pages[""] = "";
foreach ($pages as $page) {
$featpages[ $page->post_title ] = $page->ID;    
}

// creating an array of posts

$postargs = array('numberposts' => 0);
$featposts = array();
$posts = get_posts($postargs);
$posts[""] = "";
foreach ($posts as $post) {
$featposts[ $post->post_title ] = $post->ID;
}

// creating an array of activities

$actargs = array('post_type' => 'activity', 'numberposts' => 0);
$featacts = array();
$acts = get_posts($actargs);
$acts[""] = "";
foreach ($acts as $act) {
$featacts[ $act->post_title ] = $act->ID;
}

// creating a combined array of pages and tours

$links = array_merge((array)$featpages, (array)$featacts, (array)$featposts);

我希望[""] = "";for each 会在每组之间添加一个空行,但它只适用于一个 - 我猜是因为它们看起来与 array_merge 相同?

4

1 回答 1

0

[""] = "";将覆盖下一个

[] = '';改为使用

于 2012-10-25T21:10:57.433 回答