Get Achivement Date Earned
-
Hi !
How can I get the time/date related to “when the user get this achivement” (depending on achivement id).
I want the user to be abble to know when when had their achievement.
I don’t find anything related to time in the API.
Thanks for your support π
EDIT : The answer was simply on the website –‘
_badgeos_achievements Purpose: Stores a userβs earned achievements Returns: Multidimensional Array, keyed with site_id e.g. array( side_id => array( achievement_object_1, achievement_object_2, etc ) ) achievement_object ->ID ->post_type ->date_earnedCheers !
-
Here is the link :
in fact, i don’t find how to get the ‘date_earned’ knowing the achievement ID =/
I’m sure it’s pretty basic PHP but I don’t find the answer yet.Any help is welcomed π
For the user meta, there’s a meta key of
_badgeos_achievementsand within that is each achievement earned. It’s an indexed array so 0, 1, 2, 3, etcHowever, each index holds 4 named indexes, for “ID”, “post_type”, “points”, and “date_earned”
The post type is going to be the achievement type, and the ID is going to be the achievement ID. The points is how many earned, if any, and the date_earned is a UTC timestamp in seconds.
Try this out, need the achievement ID, and then the user ID:
OH ! thank you so much for this !
I wouldn’t be able to find this by myself !
I will test that tomorrow in the morning, and tell you if I succeed (but I have a good feelings about it)Thank you again, you are great !
Well you had the information, you just weren’t quite piecing together how to properly get it out of the stored meta value.
You are right, I just begin to be familiar with php but I need some help for certain things – I won’t ask you if I wan’t trying during hours π
Speaking about this custom function,
I did implement it in my website (that was the easy part)
but fore some reason it doesn’t return anything.here is my php code in my custom post type template :
<?php echo xraym_get_time_earned_by_achievement_id( $desired_achievement_id = get_the_ID(), $user_id = get_current_user_id() ); ?>It is supposed to return the date of achievement of a achievement – it is on a achievement page – depending on the current user, but it returns nothing.
Something like : “You earned that badge the *date*”Any idea ?
Still trying in waiting for your pertinent advices πtry just this:
echo xraym_get_time_earned_by_achievement_id( get_the_ID(), get_current_user_id() );That works π
I did try something harder,
to display this info in table of userHere is a screenshot of the result :
HereThis is generated by a modification of the
badgeos_get_achievement_earners_listfunction, and it is used on a custom post type of an achivement.
Here is a gist of the function.As you can see, all infos works very well (all avatars and all display name are correct) but the
xraym_get_time_earned_by_achievement_id(Date d’obtention) is displayed only for one user.
Note that if i replace the function by a simple string (such as “hello”), this string is displayed at every line.I first thought it was because achievement given by the admin were “undated” but after some test, it appears that it is not that.
What did I miss ?
thank you again for your very nice support, my sebsite is almost ready and I thank you very much for that π
I have to wonder if the returned results from
badgeos_get_achievement_earnersdon’t all have the values needed in the _badgeos_achievements user meta.My best suggestion with that is to just see what all IDs are returned by the earners function, and then double check each one’s user meta values. Should be able to do that easily enough by enabling “debug mode” in the BadgeOS settings page, and then visiting each user profile. It’ll show a print_r of the correct user meta value, last I looked. May be a minor bug if this is the case.
The debug mode doesn’t reveal me anything.
How can i see the info from the debug mode ?thanks again for your help π
the ID’s look fine as far as i know, could be be something wrong with the filters ?
For example, this is what I see on one of my user profile screens in the WP Admin with debug mode enabled.
http://cl.ly/image/3t361K0o3v3D
Ideally the IDs returned by
badgeos_get_achievement_earnerswould match the ones shown in my screenshot above, for example. If they do, then I’d check to make sure that the “date_earned” spot isn’t empty like in the screenshot above.thanks for the advice !
I saw the achievement ID in debug mode (I wasn’t looking at the right place)
I took two user : USER_1 with ACHIEVEMENT_1,
and USER_2 with ACHIEVEMENT_2 and ACHIEVEMENT_1 (in that order)the date was displayed one ACHIEVEMENT_1 page for USER_1 but not for USER_2.
I deleted USER2 ACHIEVEMENT_1, so ACHIEVEMENT_1 became its first achievement.and then, the date appears for both user.
I think it is a problem of order of achievement (when they get earned), it seems to work only for the first achievement the user got.
I had a second achievement to USER_1 and the date didn’t appear.
I think we’ve got something here. Any idea how to solve this ?
thanks again for your hard work and your patience π
Looks like I made a mistake with where I put this break at: https://gist.github.com/tw2113/8b6552c6c220a09567d4#file-gistfile1-txt-L20 It should go inside the
}a couple lines above. That way it only stops the loop iteration if it has the value needed, right now, it breaks after the first iteration regardless, which isn’t what I was aiming for. It also explains why the order of the achievements were mattering.It works !!
I also succeed to create function for author.php page wich show a table of badges earned by the author… and the earned date π
π
My website is almost ready, I can’t wait to see you how this custom functions you helped me to elaborate… or you elaborate for me (just as this one) π
Thank youuu so much !!
The topic ‘Get Achivement Date Earned’ is closed to new replies.