Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    So you want to display everyone’s badges to the non-logged in users? Or do you want to show available badges that the user could potentially earn if they join?

    If the first one, you could do a User Query and fetch/display earned achievements for each user that gets returned.

    If the latter, than your standard WP_Query would handle it fine, as achievements are just posts in post types.

    Thread Starter wagnerwillian

    (@wagnerwillian)

    I need to show everyone what each user has emblems. If I enter the profile of the “User X” will see him emlemas, even if I’m not logged in.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    aha. On User X’s profile, show his achievements to everyone.

    Not sure where exactly you’re aiming to display on the profile pages, but in terms of querying for the achievements and whatnot, I’d use badgeos_get_user_achievements() and bp_displayed_user_id()

    https://badgeos.org/api/source-function-badgeos_get_user_achievements.html#12-66

    To do the fetching, I’d do something like the following:

    $achievements = badgeos_get_user_achievements( array( 'user_id' => bp_displayed_user_id() ) );
    
    if ( !empty( $achievements ) ) {
    	foreach( $achievements as $achievement ) {
    		//Output stuff here.
    	}
    }

    The $achievements variable will be an array of achievement/post objects. With each object will be a handful of properties: “ID”, “post_type”, “points”, “date_earned”. Each will be available to display via $achievement->post_type, for example with above.

    With regards to achievement images, since they’re post types, and you have the achievement/post ID, you can use that with get_the_post_thumbnail().

    Hope that helps and gives you a good idea of how to proceed.

    Thread Starter wagnerwillian

    (@wagnerwillian)

    Hello,

    My friend, many thanks for help. I’ll try to do what you said.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display the badges for users not logged in?’ is closed to new replies.