Skip to:
Content
Pages
Categories
Search
Top
Bottom

Sorting Most favorite comments of Buddypress Group page


  • Prabin
    Participant

    @prabin04

    Hi there, I am using both BuddyPress and bbPress for my site. and I want to display the most Favorited Comments on the top on specific template. I just need a code or trick.
    Here’s the screenshot Buddypress Group Favorite Comments
    Is it possible to display the most Favorited comments from Buddypress Groups ??

    Thankx in advance 😊

Viewing 5 replies - 1 through 5 (of 5 total)

  • danbp
    Participant

    @danbp

    Hi lionel @prabin04

    no directly the solution, but you asked for code, here it is:

    https://buddypress.org/support/topic/adding-favourite-posts-as-a-tab-in-buddypress/

    No screenshot ? Anyway, on group activity page, some action to take could be:

    $my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );

    The important thing here is bp_activity_get_meta()

    Most of favorite action are related in bp-activity-actions.php, like
    $favs = bp_activity_get_user_favorites( bp_displayed_user_id() );
    also some in bp-activity-functions.php:659

    For other favorite skills, see also

    https://buddypress.trac.wordpress.org/ticket/5644


    Prabin
    Participant

    @prabin04

    @danbp thanx buddy, i’ll look-into this documentation and will ask you if i have any query..

    Thanx again .. 🙂


    Prabin
    Participant

    @prabin04

    @danbp, I have an issue..

    I have “Most Agreed” option in single group page. but the query is not returning desired value.
    can you look into this?

    Here’s the Screenshot
    Most Favourite dropdown

    and Here’s the code

    
    if( class_exists( 'BP_Group_Extension' ) ) :
    
    class bpgmq_feature_group {
    
    public function __construct() {
    $this->setup_hooks();
    }
    private function setup_hooks() {
    $bp = buddypress();
    
    add_filter( 'bp_ajax_querystring', 'custom_filter_ajax_querystring' , 999, 2 );
    // you need to do it for the group directory
    add_action( 'bp_group_activity_filter_options', array( $this, 'agreed_option' ) );
    
    }	
    public function agreed_option() {
    ?>
    <option value="featured"><?php _e( 'Most Agreed' ); ?></option>
    <?php
    }
    
    }
    
    function custom_filter_ajax_querystring( $querystring, $object ) { 
    #var_dump($querystring);
    if($object != 'activity' )
    return $querystring;
    
    $defaults = array('type'=>'active','action'=> 'active','scope'=> 'all','page'=>1,'order'=>'DESC');
    
    #exit;
    /*if( $bpgmq_querystring['type'] != 'featured' ) 
    return $querystring;*/
    $bpgmq_querystring = wp_parse_args( $querystring, $defaults );
    if( $bpgmq_querystring['type'] == 'featured' ){
    $bpgmq_querystring['meta_query'] = array(array('key'=> 'favorite_count','value'=> 1,'type'=> 'numeric','compare' => '>='));
    
    return apply_filters( 'bpgmq_filter_ajax_querystring', $bpgmq_querystring, $querystring );
    }
    var_dump($querystring);
    }
    
    function bpgmq_agreed_group() {
    if( bp_is_active( 'activity') )
    return new bpgmq_feature_group();
    }
    
    add_action( 'bp_init', 'bpgmq_agreed_group' );
    endif;

    Thanx in Advance


    danbp
    Participant

    @danbp

    Can you explain precisely what you want to do ?

    Where is this activity from ['type'] == 'featured' ?
    To use the meta favorite_count, you need the activity ID

    For example:
    $my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );

    Also, please, avoid mention me each time you have an issue, i’m not here for you only. 😉


    Prabin
    Participant

    @prabin04

    hi @danbp
    Actually, I want to display the “Most Favorited Count” in single activity group page in custom drop-down select option called “Most Agreed”. See Above Images.

    ['type'] == 'featured'
    I wanted to compare option value inside the meta_query
    <option value="featured"><?php _e( 'Most Agreed' ); ?></option>

    I am not sure if it works. can you debug this for me ? or what code i need to add ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sorting Most favorite comments of Buddypress Group page’ is closed to new replies.
Skip to toolbar