Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Post Type permalink in Activity feed


  • thirty3
    Participant

    @thirty3

    Hey,

    I’ve got a problem that I’m not sure how to correct. I have buddypress tracking custom post types 'community-story' and 'community-tip' in the activity feed. but the permalink is incorrect. it’s a simple permalink instead of a pretty one. My site default permalink structure is /%category%/%postname%/ the permalink that buddypress is displaying in the activity feed is the ?p=123 simple type.

    Where/how can I correct this problem?

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

  • Venutius
    Moderator

    @venutius

    What does your code look like thats adding the activity?


    thirty3
    Participant

    @thirty3

    Thanks for the reply!

    The code that enables the tracking is:

    add_post_type_support( 'community-story', 'buddypress-activity' );
    add_post_type_support( 'community-tip', 'buddypress-activity' );

    in bp-custom.php


    thirty3
    Participant

    @thirty3

    The code for rewriting the feed text is

    bp_activity_new_post'     => __( '%1$s shared a new <a href="%2$s">Story</a>', 'immersecommunity' ),
    bp_activity_new_post_ms'  => __( '%1$s posted a new <a href="%2$s">Story</a>, on the site %3$s', 'immersecommunity' ),

    which is part of the register_post_type('community-story') function (and mirrored in the 'community-tip' post type.)

    I’m not sure what %2$s should be changed to


    vapvarun
    Participant

    @vapvarun

    @thirty3 You can check https://buddypress.org/support/topic/custom-post-type-support-for-activity/#post-233983 it has a couple of examples of multiple cases scenarios.


    thirty3
    Participant

    @thirty3

    I just followed that link. and I have it working but the permalink is still the simple type, p=123 not the pretty type. which causes the link to break.


    vapvarun
    Participant

    @vapvarun

    @thirty3, single activity links will look like, activity/p/123 but when you click on them they will redirect with member-specific activity link


    thirty3
    Participant

    @thirty3

    That doesn’t seem to be the case. I wonder if it’s a bug since they are custom-post-types or if I just had some redundant code somewhere. I’ve got it working now though with a different method.


    thirty3
    Participant

    @thirty3

    I’ll give another example, since this appears to me to be a bug.
    Buddypress requires pretty permalinks, so why is my permalink a ?p=123 type??
    Here’s the code I’m using to add a custom post type to my activity feed.

    add_post_type_support( 'community-story', 'buddypress-activity' );
     
    function customize_page_tracking_args() {
        // Check if the Activity component is active before using it.
        if ( ! bp_is_active( 'activity' ) ) {
            return;
        }
     
        bp_activity_set_post_type_tracking_args( 'community-story', array(
            'component_id'             => 'activity',
            'action_id'                => 'new_community-story',
            'bp_activity_admin_filter' => __( 'Shared a new story', 'buddypress' ),
            'bp_activity_front_filter' => __( 'Community Story', 'buddypress' ),
            'contexts'                 => array( 'activity', 'member' ),
            'activity_comment'         => true,
            'bp_activity_new_post'     => __( '%1$s shared a new <a href="%2$s">Community Story</a>', 'buddypress' ),
            'bp_activity_new_post_ms'  => __( '%1$s posted a new <a href="%2$s">Community Story</a>, on the site %3$s', 'buddypress' ),
            'position'                 => 100,
        ) );
    }
    add_action( 'init', 'customize_page_tracking_args', 1000 );
    function record_cpt_activity_content( $cpt ) {
     
        if ( 'new_community-story' === $cpt['type'] ) {
         
            $cpt['content'] = '&nbsp;';
        }
         
     
        return $cpt;
    }
    add_filter('bp_before_activity_add_parse_args', 'record_cpt_activity_content');

    And here’s the result

    
    <p>
    <a href="https://domain.online/members/thirty3/">UserName/a> shared a new <a href="https://domain.online/?p=313">Community Story</a>
    
    <a href="https://domain.online/?p=313" class="view activity-time-since bp-tooltip" data-bp-tooltip="View Discussion"><span class="time-since" data-livestamp="2018-04-23T20:07:18+0000">17 minutes ago</span></a>
    </p>
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar