首页 > 解决方案 > 无限 wp_mail 循环

问题描述

我正在尝试使用 wp_mail 发送邮件。我做了以下事情:

add_action ('publish_party', 'party_contact_suppliers');

function party_contact_suppliers($post_id){
    $post = get_post($post_id);
    // get the address cache
    $address_cache = get_option( 'toolset_maps_address_coordinates' );
    $alerts = new WP_Query (array (
        'post_type'    => 'alert',
        'post_status' => 'publish'));
    foreach($alerts as $alert) {
    // find the address within the cache
    foreach ($address_cache as $key => $value) {
         if ( $value['address'] == $alert->center-location ) {
             $lat = $value['lat'];
             $lon = $value['lon'];
             break;
        }
    }

    $to = $alert->post_author;
    wp_mail('myemail@gmail.com','New Party Published', 'Author : '.$to.'     Latitude : '.$lat.'     Longitude : '.$lon);
}
return 0;
}

由于某种原因,这开始了邮件的无限循环。数据库中只有 2 个警报。

谁能明白为什么这只是永远循环?

标签: phpwordpress

解决方案


推荐阅读