Skip to:
Content
Pages
Categories
Search
Top
Bottom

Changing Email Content based on Situation (Taxonomy) in Code


  • bgorbett
    Participant

    @bgorbett

    I have a pretty detailed email template I want to use in BuddyPress that the email post type can’t handle even with adding my own header and footer before and after {{{content}}} in single-bp-email.php.

    What I am trying to do now is figure out how to load all the email content in single-bp-email.php and change the content within based on situation (email taxonomy). For instance, when it is a friend request, I would change my link button to {{{friend-requests.url}}} or {{{activate.url}}} when the situation is registered for account.

    Is there a reasonable way to do this? Would I iterate through the email taxonomy terms to get the default ones. Is there a list of these somewhere?

    https://codex.buddypress.org/emails/custom-emails/ is the deepest discussion on custom emails I could find.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Sounds like an interesting problem.

    You can get all the email situation terms by using a WP taxonomy function, like:

    
    $terms = get_terms( array(
        'taxonomy' => 'bp-email-type',
        'hide_empty' => false,
    ) );
    

    Though I’d probably spend a bit more time trying to make the built-in email templating system work. It’s pretty flexible, with the templing layer and the classes you can overload if necessary.


    bgorbett
    Participant

    @bgorbett

    Is it possible to determine which taxonomy is being used in single-bp-email.php using get_terms? It seems like I had it working, but now the email sends content based on all situations.


    bgorbett
    Participant

    @bgorbett

    I actually meant using get_the_terms. I am not returning any terms when using this in single-bp-email.php:
    global $post;
    $terms = get_the_terms( get_the_ID(), ‘bp-email-type’ );

    Is there a better way to determine which situation (term) is being called?

    Are you sure that get_the_ID() works in that situation (it has to be used in a loop)? What happens if you access the ID like this:

    
    global $post;
    $terms = get_the_terms( $post->ID, 'bp-email-type' );
    

    bgorbett
    Participant

    @bgorbett

    I am guessing that is the problem since neither method are returning any ID.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar