我已经为此工作了很长时间,现在我已经准备好屈服并手动完成,但是因为我已经投入了很多时间,所以我真的需要完成这个。
我有一个 csv 文件,其中包含在BuddyPress中创建群组所需的信息
我正在使用来自 bp-groups.php (http://pastie.org/1430135) 的函数和这个脚本:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
include "../../../wp-load.php";
$groups = array();
if (($handle = fopen("groupData.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$group = array('group_id' => $data[0],
'creator_id' => '1',
'name' => $data[1],
'description' => $data[2],
'slug' => groups_check_slug(sanitize_title(esc_attr($data[3]))),
'date_created' => gmdate( "Y-m-d H:i:s" ),
'status' => 'public',
'enable_forum' => '1'
);
$groups[] = $group;
}
fclose($handle);
}
foreach ($groups as $group) {
groups_create_group($group);
}
print_r($groups);
?>
从 print_r 我得到:
Array
(
[0] => Array
(
[group_id] => 2
[creator_id] => 1
[name] => GroupName1
[description] => Interesting description1
[slug] => groupname1
[date_created] => 2011-01-05 02:33:54
[status] => public
[enable_forum] => 1
)
[1] => Array
(
[group_id] => 3
[creator_id] => 1
[name] => GroupName2
[description] => Interesting description2
[slug] => groupname2
[date_created] => 2011-01-05 02:33:54
[status] => public
[enable_forum] => 1
)
)
但是,目的是从 csv 文件创建组,但事实并非如此。我究竟做错了什么?