BuddyDev

Search

[Resolved] How to Identify a Group Post

  • Participant
    Level: Enlightened
    Posts: 66
    ljmac on #4628

    Hi Brajesh,

    Tried to get an answer to this at buddypress.org but no luck as usual, but it should be a simple one for you.

    I really need a way of identifying an activity as a group post, along the lines of “if_is_group_post”. Such a function doesn’t appear to exist in BuddyPress, and surprisingly they don’t even have their own post type (just another activity update). So how can I identify an activity as a group post?

    Regards,
    Lee

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #4632

    Hi Lee,
    Thank you for posting.
    We can write a function like below to do check for ourself.

    
    function lee_is_group_activity( $activity = null ) {
    	
    	global $activities_template;
    	
    	if ( ! $activity ) {
    		$activity  = $activities_template->activity;
    	}
    	
    	if ( $activity && $activity->component == 'groups' && $activity->type == 'activity_update' ) {
    		return true;
    	}
    	
    	return false;
    }
    
    

    Hope that helps.

  • Participant
    Level: Enlightened
    Posts: 66
    ljmac on #4633

    Thanks Brajesh – that’s awesome! I like how your code is almost always very clean and comprehensible – it allows me to adapt it to various needs easily.

  • Participant
    Level: Enlightened
    Posts: 66
    ljmac on #4634

    One more thing I want to do along the same lines: identifying if an activity is an @mention, Once again there is no activity type for this – it would appear to require a search. Can you give me a similar function for this purpose?

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #4635

    Thank you Lee. It is a pleasure to help 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #4636

    Hi Lee,
    for @mention, There is no direct way to identify. It is possible to do a search on the activity_content using

    
    bp_activity_find_mentions( $content)
    

    This function will return an array of mentioned user names or false if none found.

    Hope you can take from there.

    PS: Doing an search for mention on all activity will not be very efficient, I will recommed another approach(Like when the activity is created, check for mention and store a meta, then use this meta later).

    Hope that helps.

  • Participant
    Level: Enlightened
    Posts: 66
    ljmac on #4637

    Thanks again Brajesh – you’re a champion.

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #4638

    Thank you for the kind words 🙂

The topic ‘ [Resolved] How to Identify a Group Post’ is closed to new replies.

This topic is: resolved