BuddyDev

Search

Replies

  • Participant
    Level: Guru
    Posts: 907
    Tosin on in reply to: Buddyblog assign taxonomy on update #55425

    This is the code that worked for me

    /**
     * Assign "Sponsored Posts" content type if post is marked as sticky.
     */
    function assign_sponsored_term_if_sticky( $post_id, $form_id, $post_data ) {
    	// Check if post is sticky.
    	if ( ! is_sticky( $post_id ) ) {
    		return;
    	}
    
    	// Get the "Sponsored Posts" term in 'content_type' taxonomy.
    	$term = get_term_by( 'name', 'Sponsored Posts', 'content_type' );
    	if ( ! $term || is_wp_error( $term ) ) {
    		return;
    	}
    
    	// Append the term to the post without removing other terms.
    	wp_set_post_terms( $post_id, array( $term->term_id ), 'content_type', true );
    }
    add_action( 'bblpro_post_submitted', 'assign_sponsored_term_if_sticky', 20, 3 );
    add_action( 'bblpro_post_updated', 'assign_sponsored_term_if_sticky', 20, 3 );  

    I dont know why this code below did not work

     /**
     * Reassign "Sponsored Posts" term when a paid post is submitted or updated.
     */
    function assign_sponsored_term_if_paid( $post_id, $form_id, $post_data ) {
    	// Check if the post is paid.
    	if ( ! bbl_ppp_get_post_order_id( $post_id ) ) {
    		return;
    	}
    
    	// Get the "Sponsored Posts" term.
    	$term = get_term_by( 'name', 'Sponsored Posts', 'content_type' );
    	if ( ! $term ) {
    		return;
    	}
    
    	// Append the term without removing existing ones.
    	wp_set_post_terms( $post_id, array( $term->term_id ), 'content_type', true );
    }
    add_action( 'bblpro_post_submitted', 'assign_sponsored_term_if_paid', 20, 3 );
    add_action( 'bblpro_post_updated', 'assign_sponsored_term_if_paid', 20, 3 );
     
  • Participant
    Level: Guru
    Posts: 907
    Tosin on in reply to: Buddyblog assign taxonomy on update #55424

    Thanks Brajesh

    This is the code I used can you confirm if its accurate

     /**
     * Assign (Sponsored Post) category to BuddyBlog pay per post articles on checkout.
     */
    function assign_sponsored_term_if_paid( $post_id, $form_id ) {
    	if ( 'post' !== get_post_type( $post_id ) ) {
    		return;
    	}
    
    	// Check if post is a paid post by checking if order ID exists.
    	$order_id = get_post_meta( $post_id, '_bblpro_ppp_order_id', true );
    	if ( ! $order_id ) {
    		return;
    	}
    
    	// Get the Sponsored Posts term.
    	$term = get_term_by( 'name', 'Sponsored Posts', 'content_type' );
    	if ( ! $term || is_wp_error( $term ) ) {
    		return;
    	}
    
    	// Assign Sponsored Posts term to the post (merge with existing).
    	wp_set_post_terms( $post_id, array( $term->term_id ), 'content_type', true );
    }
    add_action( 'bblpro_post_submitted', 'assign_sponsored_term_if_paid', 20, 2 );
    add_action( 'bblpro_post_updated', 'assign_sponsored_term_if_paid', 20, 2 );  

    Thanks

  • Participant
    Level: Guru
    Posts: 907
    Tosin on in reply to: Buddyblog assign taxonomy on update #55403

    1. I created a custom taxonomy called CONTENT TYPE where by (Sponsored Posts) is an option.

    2. I now disabled the (Sponsored Posts) option in the buddyblog settings because I don’t want users to be select this option when posting.

    3. I only want the (Sponsored Posts) option to be automatically assigned only to featured paid post using the code I shared above. IM USING PAY PER POST ADDON

    THE PROBLEM

    1. The problem now is with the retention/removal of the (Sponsored Posts) term to published paid post when users try to edit and republish a paid post.

    2. If I edit a paid post the (Sponsored Posts) term is removed after clicking the (UPDATE) button.

    3. When editing a paid post the term (Sponsored Posts) should not be removed as the term was initially assigned using the code I provided

  • Participant
    Level: Guru
    Posts: 907
    Tosin on in reply to: Buddyblog assign taxonomy on update #55287

    Gentle reminder sir thanks

  • Participant
    Level: Guru
    Posts: 907

    Thanks Brajesh

    Your code worked perfectly.

  • Participant
    Level: Guru
    Posts: 907

    Thanks for the feedback ill stick to your advice

  • Participant
    Level: Guru
    Posts: 907

    Hi Barjesh

    Can you provide the same code(Limit message to one participant) for the legacy template

  • Participant
    Level: Guru
    Posts: 907

    Thanks Ravi this is now resolved

  • Participant
    Level: Guru
    Posts: 907

    Thanks for the updated code

    I am using the profile privacy plugin and while using your updated code I am receiving the 404 error correctly but the url is in this format https://site.com/members/mike/visibility-protected/.

    I dont think it’s cool to show the (visibility-protected) slug for admins since it reveals that the admin account is available but just hidden

  • Participant
    Level: Guru
    Posts: 907
    Tosin on in reply to: Buddyblog Suggestion #53014

    maybe adding the POST FORM slug parameter or form ID to the shortcode would be an option see example below

    [bbl-create-by-post-type post_type=’post’ slug=’admin-post-form’]

    [bbl-create-by-post-type post_type=’post’ slug=’subscriber-post-form’]