Help with creating, using and deleting metadata

   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,

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking