Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to count number of favorites for any activity


  • mahdiar
    Participant

    @mahdiar

    Hi
    Is there any way to show how many people favorited one activity ? only number I mean .
    e.g. 3 persons favorited this activity.

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

  • danbp
    Moderator

    @danbp

    hi @mahdiar,

    of course there is a way ! 😉

    Add this to bp-custom.php, and tell us if it is what you needed

    
    function bpfr_fav_count() {
    	
    	// bail if activity component is not used
    	if ( !bp_is_active( 'activity' ) ) {
    		return false;
    	}
    
    	// action
    	$my_fav_count = bp_activity_get_meta( bp_get_activity_id(), 'favorite_count' );
    
    	// formating action result
    	if ( ! empty( $my_fav_count ) ) {
    		$text = sprintf( _n( 'Favorited by %d user.', 'Favorited by %d users.', $my_fav_count, 'text_domain' ), bp_core_number_format( $my_fav_count ) );	
    	}
    	
    	// output
    	echo $text;
    }
    add_action( 'bp_activity_entry_meta', 'bpfr_fav_count' );

    mahdiar
    Participant

    @mahdiar

    Thanks a lot !!
    I’m developing BSALA plugin So I need it very much .


    michaelpfaff
    Participant

    @michaelpfaff

    Dan, is there a way to count up the number of favorites for all activity and create a stream of “Most Favorited”?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to count number of favorites for any activity’ is closed to new replies.
Skip to toolbar