Replies
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 );
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
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
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