I am very new to elgg, so please be gentle and pardon me for any dumb questions. I have a few very basic questions about storing metadata. For each user I want to have a new field called creds (short for credits). I want to store the values as metadata. So this is what I did. I added the following piece of code where I wanted to create the metadata (and/or modify it, if it exists)
$user = get_loggedin_user();
if (!isset($user->creds))
{
$user->creds = 0;
}
else
{
$user->creds++;
}
Then at the place where I want to access the value of the newly created metadata ('creds') I just do the following :-
$user = get_loggedin_user();
if (isset($user->creds))
{
echo $user->creds;
}
My question is :-
(a) How do I delete this metadata if I want to ?
(b) The following reference page for elgg apis
http://reference.elgg.org/engine_2lib_2metadata_8php.html#a1614d620ec0b0d0b9531c68070ffb33c
talks about about apis like elgg_get_metadata_from_id($id) and elgg_delete_metadata_by_id($id). I want to use these APIs but how do I get the id of the metadata that I created above ?
(c) Are the elgg user docs outdated or am I missing something? The following website
http://docs.elgg.org/wiki/Engine/DataModel/Metadata#Trying_to_store_hashmaps
gives examples like the following "$dob = get_metadata_byname($user_guid, 'dob')"; However when I try to use the api get_metadata_by_name I get an error message saying that the api is outdated. I am using elgg1.8
(d) If there are alternate ways of creating, using and deleting metadat, then any examples or pointers would be most appreciated
Thanks in advance for all your help,
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Matt Beckett@Beck24

Matt Beckett - 0 likes
- psman@psman

psman - 0 likes
You must log in to post replies.Yes it seems some of the docs are still out of date, I've been updating the ones I find out of date occasionally as time permits. I'll add that to the list.
You are correct about creating metadata, the easiest way is just to declare it as an attribute of the entity.
To delete it you can use the entity method
$user->deleteMetadata('creds');
see api docs: http://reference.elgg.org/1.8/classElggEntity.html#a9bef5522f3429d7297c220fef40ff082
Personally I find the api docs the most helpful, just make sure you're looking at the 1.8 version - which will also tell you to use elgg_get_logged_in_user_entity() instead of get_logged_in_user()
Matt, thanks for your inputs. This is very helpful