WordPress.org

Ready to get started?Download WordPress

Forums

Show taxonomy in buddypress activity stream (3 posts)

  1. caustix
    Member
    Posted 1 year ago #

    I'll like to add the information of the taxonomy (city name) in the buddypress activity stream.

    I succeeded to include the category with this code:

    add_filter('bp_blogs_activity_new_post_action', 'record_cpt_activity_action', 1, 3);
    function record_cpt_activity_action( $activity_action,  $post, $post_permalink ) {
            global $bp;
    	$category = get_the_category($post->ID);
    	if( $post->post_type == 'recos' ) {
                           $activity_action  = sprintf( __( '%1$s wrote a new post in the category %3$s : %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>');
            }
            return $activity_action;
    }

    I tried this to ad the taxonomy but it doesn't works

    add_filter('bp_blogs_activity_new_post_action', 'record_cpt_activity_action', 1, 3);
    function record_cpt_activity_action( $activity_action,  $post, $post_permalink ) {
            global $bp;
    	$category = get_the_category($post->ID);
    	$terms = get_the_terms($post->ID, 'taxo_city');
    	$thecity = $terms[0]->name; 
    
    	if( $post->post_type == 'recos' ) {
    
                           $activity_action  = sprintf( __( '%1$s wrote a new post in %3$s : %2$s at %4$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>',$thecity);
            }
            return $activity_action;
    }

    any ideas?

  2. caustix
    Member
    Posted 1 year ago #

    No one? I can store the data in custom field if it's easier to make it works.
    But the code following doesn't work neither :
    $thecity = get_post_meta($post->ID,'customfield_city',true);
    Please help!

  3. leoreiki
    Member
    Posted 10 months ago #

    How (and where) do you include the first code to show Category post on activity stream?
    I was search in all foruns to this solution...

Topic Closed

This topic has been closed to new replies.

About this Topic