Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Create new Post on updating Activities


  • pokhsujan
    Participant

    @pokhsujan

    Hi everyone,

    Is there any way to create a new post (custom post type), while posting an activity?
    What I need is to create a different Custom Post Type called activit feed which will be auto created for each activity update.
    When any user posts an update in the activity section, a new posts should be created with the details added in the activity update.
    Please Help.

    Thanks.

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

  • Henry Wright
    Moderator

    @henrywright

    The bp_activity_add action fires at the end of adding a new activity item. So you can hook a custom function to that and add your custom post within that. Here’s an example:

    add_action( 'bp_activity_add', function( $r ) {
    
        // Insert a new post.
        wp_insert_post(
            array(
                'post_type' => 'activitfeed',
                'post_title' => __( 'Hello world', 'text-domain' ),
                'post_content' => $r['content'],
                'post_status' => 'publish'
            )
        );
    } );

    Ref: https://developer.wordpress.org/reference/functions/wp_insert_post/


    pokhsujan
    Participant

    @pokhsujan

    Thank You @Henry,
    I did my task using another hook though. I used bp_activity_posted_update hook to accomplish the task.
    Thank you very much for your reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar