str_replace not preserving whitespace

Did you clear cache after making changes with trim()? Try with: str_replace( trim( $parent->name ), $link, $intro_text ); Are you sure that the term is Upbeat Electronic music and not UpbeatElectronic music? Try with this to be sure: str_replace( trim( $parent->name ), ‘ ‘ . $link, $intro_text );

Add tags to a “pending” post before publishing

The @PieterGoosen’s answer saved my life: add_action( ‘transition_post_status’, function ( $new_status, $old_status, $post ) { if( ‘publish’ == $new_status && ‘advert_tmp’ == $old_status && $post->post_type == ‘advert’ ) { $tags = get_post_meta( $post->ID, ‘advert_tags_field’, true ); $tags = explode( ‘,’, $tags ); if( !empty( $tags ) ) { wp_set_object_terms( $post->ID, $tags, ‘advert_tag’ ); delete_post_meta( $post->ID, … Read more