BuddyDev

Search

[Resolved] BuddyBlog pay per post – remove post from category on expiration

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

    Hello,

    I have this code in my site to assign paid posts into the sponsored post category but how can I achieve the opposite

    – Remove or unset paid sticky posts from the (Sponsored Posts) content_type category when the paid post expires.

     /**
     * Assign (Sponsored Post) category to BuddyBlog pay per post articles on checkout.
     */
    add_action( 'bblpro_ppp_post_purchase_completed', function( $post_id ) {
    	$post_type = get_post_type( $post_id );
    	if ( 'post' !== $post_type ) {
    		return;
    	}
    	// Get taxonomy term.
    	$newterm = get_term_by( 'name', 'Sponsored Posts', 'content_type' );
    	if ( ! $newterm ) {
    		return;
    	}
    	// Assign term to post.
    	wp_set_post_terms( $post_id, $newterm->term_id, 'content_type', true );
    } ); 

    Note (content_type) is a custom taxonomy

    now how can I automatically remove sticky posts from the Sponsored Post on expiration

    Thanks

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

    Hi Tosin,
    Thank you for the question.

    You may try the following.

    
    
    add_action( 'bblpro_ppp_purchased_post_expired', function ( $post_id ) {
    
    	$post_type = get_post_type( $post_id );
    	if ( 'post' !== $post_type ) {
    		return;
    	}
    	wp_remove_object_terms( $post_id, 'Sponsored Posts', 'content_type' );
    } );
    
    

    Also, you may change the term name with the term slug for better result.

    Regards
    Brajesh

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

    Thank you Brajesh

    this is now resolved

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

    You are welcome.

The topic ‘ [Resolved] BuddyBlog pay per post – remove post from category on expiration’ is closed to new replies.

This topic is: resolved