我使用函数与其他用户共享书签集合,我需要在WordPress中创建新项目后获取id 用户专业书签插件
function share_collection($id,$name,$cbcolor,$user) {
$user_id = get_user_by( 'email', $user );
$user_id_current = get_current_user_id();
$collectionscurrent = $this->get_collections($user_id_current);
$collections = $this->get_collections($user_id->ID);
$collections[] = array('label' => $name);
// transfer bookmarks to shared collection
foreach($collectionscurrent[$coll_id] as $k => $arr) {
if ($k != 'label') {
$collections["This is where id should go"][$k] = 1;
}
}
update_user_meta($user_id->ID, '_wpb_collections', $collections);
}
我如何检索从 $collections[] = array('label' => $name) 创建的 id;并在我提到"这是 id 应该去的地方"的地方使用它
get_collections功能如下
function get_collections($user_id) {
return (array)get_user_meta($user_id, '_wpb_collections', true);
}
提前感谢!
它
被称为数组索引。假设$collections
是基于零的数字数组,其中没有任何"孔"(孔将是例如索引 1 in [0 => 'a', 2 => 'b']
),您可以使用:
$collections[] = array('label' => $name);
$idx = count($collections) - 1;
如果它不是数字或可能有孔,你必须首先找出要使用的索引:
$idx = count($collections);
$collections[$idx] = array('label' => $name);