paulgibbs / achievements

Achievements gamifies your WordPress site with challenges, badges, and points.
http://achievementsapp.com
63 stars 9 forks source link

Achivment Categories filter #144

Open drudnev opened 9 years ago

drudnev commented 9 years ago

Is there a way to do a category based filter, can someone post an example how this can be done? https://wordpress.org/plugins/display-posts-shortcode/ Doesn't seem to pickup achievements:

[display-posts post_type="achievement" category="must-read" ]

I was trying to add add filter to short codes to in mean time but its not working either it seems that query gets reset , can't figure out where ( pardon the n00b).

    public function display_category_achievements( $attr, $content='') {

        // Sanity check required info
        if ( ! empty( $content ) || empty( $attr['category_name'] ) )
            return $content;

        $this->unset_globals();
        $this->start( 'dpa_achievement_archive' );

        achievements()->achievement_query->query_vars['post_type'] = dpa_get_achievement_post_type();
        achievements()->achievement_query->query_vars['category_name'] = $attr['category_name'];

        dpa_get_template_part( 'content-archive-achievement' );
        return $this->end();

thank you for you help in advance.

drudnev commented 9 years ago

Found a working solution if anyone is interested, feel free to comment. ln:51

            // Specific Category achievement - pass an 'id' attribute
            'dpa-category-achievements'      => array( $this, 'display_category_achievements' ),

And the actual function.


    /**
     * For the current category, display an index of all the achievements
     * in an output buffer and return to ensure that post/page contents are displayed first.
     *
     * @param array $attr
     * @param string $content Optional
     * @return string Contents of output buffer
     * @since Achievements (3.0)
     */
    public function display_category_achievements( $attr, $content='') {
        $this->unset_globals();
        // Sanity check required info
        if ( ! empty( $content ) || empty( $attr['category_name'] ) )
            return $content;
        $this->start( 'dpa_category_achievement_archive' );
        achievements()->achievement_query->in_the_loop             = true;
        dpa_has_achievements( array( 'category_name' => $attr['category_name'] ) );

        while ( dpa_achievements() ) {
            dpa_the_achievement();
            dpa_get_template_part( 'loop-single-achievement' );

        } 
        return $this->end();
    }
paulgibbs commented 9 years ago

Hi

Thanks for writing. I'm not currently supporting or working on this plugin, so I'm going to leave your comments here in case anyone else is trying to do the same thing and finds it.

Thanks again for using Achievements!


Paul Gibbs

On 2 Jul 2015, at 06:11, drudnev notifications@github.com wrote:

Found a working solution if anyone is interested, feel free to comment. ln:51

        // Specific Category achievement - pass an 'id' attribute
        'dpa-category-achievements'      => array( $this, 'display_category_achievements' ),

And the actual function.

/**
 * For the current category, display an index of all the achievements
 * in an output buffer and return to ensure that post/page contents are displayed first.
 *
 * @param array $attr
 * @param string $content Optional
 * @return string Contents of output buffer
 * @since Achievements (3.0)
 */
public function display_category_achievements( $attr, $content='') {
    $this->unset_globals();
    // Sanity check required info
    if ( ! empty( $content ) || empty( $attr['category_name'] ) )
        return $content;
    $this->start( 'dpa_category_achievement_archive' );
    achievements()->achievement_query->in_the_loop             = true;
    dpa_has_achievements( array( 'category_name' => $attr['category_name'] ) );

    while ( dpa_achievements() ) {
        dpa_the_achievement();
        dpa_get_template_part( 'loop-single-achievement' );

    } 
    return $this->end();
}

— Reply to this email directly or view it on GitHub.