Up to 50 percent off

Include custom taxonomy in notification

This topic contains 2 reply and 2 voices, and was last updated by gpspake 10 years, 11 months ago
Viewing 2 Posts - 1 through 2 (of 2 total)
Author Posts
November 12, 2013 at 2:15 am 9971
gpspake In the Notification options, you can select %category% to display the selected categories. Is there a way to do the same thing with a custom taxonomy?
November 26, 2013 at 9:08 pm 12887
Tareq Hasan Tareq Hasan

Hey George,

Sorry I missed the topic at all. There is no currently filters available so you can’t change it without modifying the code.

November 27, 2013 at 1:51 am 12899
gpspake gpspake

Yeah, sorry I meant to jump in here and post this in case anyone is interested…

This does require code modification but, if you really need it, it’s fairly simple. Ideally, these options would be abstracted and there would be a filter but considering this is sort of a bonus feature in this plugin, it’s not really necessary. In my example, the actual taxonomy could be abstracted (Kind of like the custom field option) but, since I only needed one custom taxonomy, I just hard coded it.

Note – This is for 2.1.7 but I’m sure the same applies to 2.1.8

To add custom taxonomies to the notification email, you just need to add a few lines to class/frontend-form-post.php

In the prepare_mail_body function there is an array of options (assigned to $post_field_replace) with variables you should recognize from the notification page in the form builder (ex: %post_title%’, ‘%post_content%’, etc..).

These variables correspond to the values set in the array below ($post_field_replace). It should be pretty clear how this works by looking at the code.

So, all you really need to do is add ‘%taxonomy%’ to the $post_field_replace array and add $this->pending_post_count( ‘mycustomtaxonomy’ ) to the corresponding place in the $post_field_replace array.

In the end it should look like this…

$post_field_search = array( '%post_title%', '%post_content%', '%post_excerpt%', '%pending_post_count%' ,'%tags%', '%category%', '%taxonomy%',
    '%author%', '%sitename%', '%siteurl%', '%permalink%', '%editlink%' );

$post_field_replace = array(
    $post->post_title,
    $post->post_content,
    $post->post_excerpt,
    $this->pending_post_count( 'mycustomtaxonomy' ),
    get_the_term_list( $post_id, 'post_tag', '', ', '),
    get_the_term_list( $post_id, 'category', '', ', '),
    get_the_term_list( $post_id, 'listserv', '', ', '),
    $user->display_name,
    get_bloginfo( 'name' ),
    home_url(),
    get_permalink( $post_id ),
    admin_url( 'post.php?action=edit&post=' . $post_id )
);

Obviously, this will work for other things as well as taxonomy too.
Hope this helps…

Viewing 2 Posts - 1 through 2 (of 2 total)