Support » Plugin: Achievements for WordPress » User Achievements Index Not Displaying

  • Resolved whatupbp


    Hello WP community,

    I’m attempting to display the user’s list of achievements using the shortcode [], but the only thing that appears is…

    This is somewhat embarrassing, isn’t it? No achievements were found.

    Any assistance would greatly be appreaciated! : )

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Paul Gibbs


    Sorry, which shortcod? The forum here ate it. (try not putting it in the square brackets.

    Also where are you using the shortcode? Adding it into a page or a post?

    I’m having the same issue.

    I’m using the following code in a template page:

    <h2 class="entry-title"><?php _e( 'Achievements', 'achievements' ); ?></h2>
    	echo do_shortcode('[dpa-user-achievements-index]');

    A little more background: I am using this shortcode on the bbpress profile page of users. The problem seems to be that the shortcode relies on the author of the page. Is there a way to pass in a user ID to override the author requirements?


    After a bit more digging, I have come to the conclusion that it fails because it doesn’t detect the userid on the profile page. The following snippet should help with this, but I don’t know where in the achievement code to apply it:
    bbp_get_user_id( 0, true, false );

    I have tested this in various parts of the achievement code with success in that it prints out the code, but the if statement
    if ( dpa_has_progress() && ! empty( achievements()->achievement_query->posts ) )
    still fails in content-author-achievement.php.
    I tried in spa_has_achievements, but that function wasn’t even being fired.
    Any thoughts where this check is failing would be appreciated.

    Should I create a new post for this issue?


    @ mikebronner
    Hello there. Are you adding these scripts to the plugin php files or are you using shorcodes [] in a page? I am trying to create the user achievemnets’ page too, but I do not know php (trying to learn the basics through a course now), so this is not that obvious to me. Thanks a lot

    Hi Ionna,

    I am inserting the following code in a page template for user profiles on my child theme:

    <h2 class="entry-title"><?php _e( 'Achievements', 'achievements' ); ?></h2>
    	echo do_shortcode('[dpa-user-achievements-index]');

    Unfortunately this shortcode doesn’t run correctly if the page in question doesn’t have an author associated with it. You should be able to use this in any normal page template, though.

    Thanks very much Mike. I’ll try it out πŸ™‚

    Plugin Author Paul Gibbs


    The problem seems to be that the shortcode relies on the author of the page. Is there a way to pass in a user ID to override the author requirements?

    Yes, but not trivial. Look at DPA_Shortcodes->display_user_achievements() in includes/class-dpa-shortcodes.php. It loads the content-author-achievement.php template. In that, the main stuff is a call to dpa_has_progress(). If you look at dpa_has_progress() in includes/progress/template.php, line 43ish there’s an “author” parameter (just like the standard WordPress loop).

    In theory copying the contents of the template into your theme file, and adding the author parameter based on your requirements, should do the job.

    Hi Paul, thanks so much for responding. πŸ™‚

    This is the what I get in $defaults when I run it on the profile page:
    array(11) { ["max_num_pages"]=> bool(false) ["order"]=> string(4) "DESC" ["orderby"]=> string(4) "date" ["paged"]=> int(1) ["post_status"]=> string(12) "dpa_unlocked" ["post_type"]=> string(12) "dpa_progress" ["s"]=> string(0) "" ["author"]=> int(1) ["post_parent"]=> NULL ["posts_per_page"]=> int(-1) ["ach_populate_achievements"]=> bool(false) }

    And here is what I get when I run it on the achievements page using the unaltered code:
    array(11) { ["max_num_pages"]=> bool(false) ["order"]=> string(4) "DESC" ["orderby"]=> string(4) "date" ["paged"]=> int(1) ["post_status"]=> string(12) "dpa_unlocked" ["post_type"]=> string(12) "dpa_progress" ["s"]=> string(0) "" ["author"]=> int(0) ["post_parent"]=> NULL ["posts_per_page"]=> int(-1) ["ach_populate_achievements"]=> bool(true) }

    To get around the ach_populate_achievements being false, I modified that setting to always be true on that given template for profiles. Voila, it worked!

    So, to avoid having to duplicate the dpa_has_progress function, I realized I can acutally pass in the parameters I need (thanks for the clean coding allowing for this!), like so:
    if ( dpa_has_progress(array("author"=>bbp_get_user_id( 0, true, false ), "ach_populate_achievements"=>true)) && ! empty( achievements()->achievement_query->posts ) )

    Thanks for giving me the nudge in the right direction, now I know how to do this for any page. πŸ™‚ Hopefully this will help others as well.

    Here is a link to what I was working on. The medals and ribbons are just examples, we will be updating the graphics to be uniform and align nicely:

    Plugin Author Paul Gibbs


    Good job! I’ll consider adding support for bbPress profile page user IDs in the future (we’ll see!).

    I’m trying to bring the members achievements to profile.php page like Mike, i guess πŸ™‚

    Paul: Do you mean to copy the template.php or content-author-achievement.php? And then add the author parameter? I’m doing like this in my profile.php but not manage to get it work.

    <?php do_action( 'dpa_template_before_author_achievements' ); ?>
    <?php if ( dpa_has_progress(array("author"=>’ . $bp->displayed_user->id)) && ! empty( achievements()->achievement_query->posts ) ) : ?>
    <?php dpa_get_template_part( 'pagination-author-achievements' ); ?>
    <?php dpa_get_template_part( 'loop-achievements'              ); ?>
    <?php dpa_get_template_part( 'dpa_single_user_achievements' ); ?>
    <?php else : ?>
    <?php dpa_get_template_part( 'feedback-no-achievements' ); ?>
    <?php endif; ?>
    <?php do_action( 'dpa_template_after_author_achievements' ); ?>

    Mike: How did you manage to bring in the defaults? Am I suppose to do it here in profile.php? I’m not sure how to use your code.

    Thanks for any help!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘User Achievements Index Not Displaying’ is closed to new replies.