Skip to:
Content
Pages
Categories
Search
Top
Bottom

BUDDYPRESS CUSTOM POST ACTIVITY FEED


  • doctrpnyc
    Participant

    @doctrpnyc

    Hello. i am using the below code to display new jobs added to the activity field. i want to display the job post title in the feed but it shows as just job. i am using the following code

    bp_activity_set_post_type_tracking_args( ‘job_listing’, array(
    ‘component_id’ => ‘activity’,
    ‘action_id’ => ‘new_job_listing’,
    ‘bp_activity_admin_filter’ => __( ‘admin Jobs’, ‘custom-domain’ ),
    ‘bp_activity_front_filter’ => __( ‘Jobs’, ‘custom-domain’ ),
    ‘contexts’ => array( ‘activity’, ‘member’ ),
    ‘bp_activity_new_post’ => __( ‘%1$s posted a new work opportunity Job‘, ‘drallys’ ),
    ‘bp_activity_new_post_ms’ => __( ‘%1$s posted a new work opportunity Job, on the site %3$s’, ‘drallys’ ),
    ‘position’ => 100,
    ) );
    }
    add_action( ‘init’, ‘customize_page_tracking_args’, 1000 );

    function monkey1980_include_post_type_title( $action, $activity ) {
    if ( empty( $activity->id ) ) {
    return $action;
    }

    if ( ‘new_job_listing’ != $activity->type ) {
    return $action;
    }

    preg_match_all( ‘/<a.*?>([^>]*)<\/a>/’, $activity->action, $matches );

    if ( empty( $matches[1][1] ) || ‘Job’ != $matches[1][1] ) {
    return $action;
    }

    $post_type_title = bp_activity_get_meta( $activity->id, ‘post_title’ );

    if ( empty( $post_type_title ) ) {
    switch_to_blog( $activity->item_id );

    $post_type_title = get_post_field( ‘post_title’, $activity->secondary_item_id );

    // We have a title save it in activity meta to avoid switching blogs too much
    if ( ! empty( $post_type_title ) ) {
    bp_activity_update_meta( $activity->id, ‘post_title’, $post_type_title );
    }

    restore_current_blog();
    }

    return str_replace( $matches[1][1], esc_html( $post_type_title ), $activity->action );
    }
    add_filter( ‘bp_activity_custom_post_type_post_action’, ‘monkey1980_include_post_type_title’, 10, 2 );

  • You must be logged in to reply to this topic.
Skip to toolbar