BuddyDev

Search

[Resolved] Buddyblog change author if post is published in a specific category

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #44967

    Hello,

    I have a post category called (Anonymous posts) and a user called (anonymous), If any logged in user select the category (Anonymous posts) and publish, then automatically change the logged in author to another author called (anonymous).

    This change should only occur upon clicking (publish) and should not occur when post is saved as (draft)

    This is an edited example from your code

     /**
     * Update BuddyBlog Author when a post is submitted in a specific category.
     */
    add_filter( 'bblpro_post_submission_prepared_data', function ( $post_data, $cat_id, $post, $is_submission ) {
    	// update author if the category was selected. Don't do anything on edit.
    	if ( $is_submission && 1487 === (int)$cat_id ) {
    		$post_data['post_author'] = 4766806;
    		// keep current user data for future?
    		if ( ! empty( $post_data['ID'] ) ) {
    			update_post_meta( $post_data['ID'], '_bbl_original_post_author', get_current_user_id() );
    		}
    	}
    	return $post_data;
    }, 10, 4 ); 
  • Participant
    Level: Guru
    Posts: 885
    Tosin on #45017

    Gentle reminder sir

    Thanks

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #45053

    Hello Brajesh,

    Please any update thanks a lot

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #45056

    Hi Tosin,
    I will need couple of days to have setup and test your code in order to assist you with it. I will be replying sometimes this week after testing.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #45059

    I already tested the code but it did not work

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #45060

    That’s what I am referring to. The code you have supplied may not be suitable and I will need to try my update on a local setup.

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #45153

    Kind reminder sir

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #45166

    Hi Tosin,
    Sorry, I could not help you earlier.

    1. Do you want to limit the scope of this update to certain form? If yes, Please share the form id.
    2. By category, are you referring to post category or is it a custom taxonomy? If it is a custom taxonomy, Please let me know about the name and label.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #45182

    1. No I dont want to limit the scope, this update should be applicable to all forms

    2. Yes i’m referring to post category (category id = 1487) while use ID that will inherit the submitted post = 4766806

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #45189

    Thank you Tosin,
    I will be sharing code soon.

    Regards
    Brajesh

The topic ‘ [Resolved] Buddyblog change author if post is published in a specific category’ is closed to new replies.

This topic is: resolved