根据分类术语发送电子邮件

时间:2019-11-14 作者:MFWebMaster

如果自定义帖子创建/更新了自定义分类法,我喜欢发送电子邮件term.

这里是CPT、分类法和术语。

自定义帖子类型:Call自定义分类法:Call\\u类型自定义术语:正在进行中,下面的代码仅适用于基于CTP发送邮件。

////////////////////////////////////////////////////////////////////
//  Add Hooks for Email 
////////////////////////////////////////////////////////////////////
add_action(\'new_to_publish\', \'send_emails_on_new_event\');
add_action(\'post_updated\', \'send_emails_on_new_event\');
////////////////////////////////////////////////////////////////////
//  SET EMAIL FROM ADDRESS
////////////////////////////////////////////////////////////////////
function change_mail_from() {
    return "[email protected]";
}
add_filter ("wp_mail_from", "change_mail_from");
////////////////////////////////////////////////////////////////////
//  SET EMAIL FROM NAME
////////////////////////////////////////////////////////////////////
function change_from_name() {
    return "ABC";
}
add_filter ("wp_mail_from_name", "change_from_name");
////////////////////////////////////////////////////////////////////
//  SET EMAIL TYPE TO HTML
////////////////////////////////////////////////////////////////////
function wpse27856_set_content_type(){
    return "text/html";
}
add_filter( \'wp_mail_content_type\',\'wpse27856_set_content_type\' );
////////////////////////////////////////////////////////////////////
//  Send emails on event publication
////////////////////////////////////////////////////////////////////

function send_emails_on_new_event($post_id)
{
    global $post;
    $post           =   get_post($post_id);
    $post_id        =   $post->ID;
    $post_type      =   \'call\'; //post, page, attachment or whatever other CPT you may have
    $post_term      =   \'\'
    $author         =   get_userdata($post->post_author);
    $mf_area        =   $author->mf_area;
    $author_mail    =   $author->user_email;
    $author_name    =   $author->mf_d_name;
    $ac_name        =   get_post_meta( $post_id, \'_call_8\', true);
    $ac_email       =   get_post_meta( $post_id, \'_call_9\', true);
    $rc_email       =   get_post_meta( $post_id, \'_call_12\', true);
    $rc_name        =   get_post_meta( $post_id, \'_call_13\', true);
    $mtm_email      =   \'[email protected]\';
    $emails         =   "$author_mail, $ac_email, $mtm_email"; //If you want to send to site administrator, use $emails = get_option(\'admin_email\');
    $title          =   wp_strip_all_tags(get_the_title($post_id,));
    $url            =   home_url();
    ////////////////////////////////////////////////////////////////////
    //  Email lay out
    ////////////////////////////////////////////////////////////////////   
    ob_start(); ?>
    <html>
        <head>
            <style>
                a {
                    color: #ff3333;
                    font: 1.5rem;
                    line-height: 2rem;
                    text-decoration: none;
                    }
            </style>
        </head>
        <body>
            <p>
                Hi 
            </p>
            <p>
                Ref number <?php echo $title ;?> has been created.
            </p>

            <p>
                <strong>Details:</strong><br />
                <a href="<?php echo $url ;?>">Log in to track this call.</a><br/>
            </p>
            <p>
                Regards,<br />
                ABC
            </p>
        </body>
    </html>
    <?php
    $message = ob_get_contents();
    ob_end_clean();
    if(get_post_type($post) === $post_type)
    wp_mail($emails, "New Item listed on Fit It List. Ref number $title", $message);
}
////////////////////////////////////////////////////////////////////
//  End Fire mail on post page and CPT
////////////////////////////////////////////////////////////////////
有没有人能帮我把剧本也写下来。

1 个回复
SO网友:butlerblog

您是否尝试过使用has_term()?

if( get_post_type($post) === $post_type && has_term( \'In progress\', \'call_type\', $post ) )
    wp_mail($emails, "New Item listed on Fit It List. Ref number $title", $message);

相关推荐

Cron not sending wp-mail()

我对cron计划功能有问题,它不想用wp_mail() 作用This is my code:它被放置在函数中。php<?php add_filter(\'cron_schedules\', \'add_review_invites_schedule\'); function add_review_invites_schedule($schedules){ $schedules[\'send_review_invites_interva