我现在使用的是“The Events Calendar“我的网站上的插件,用于协调员工团队。我希望能够自动发送包含活动帖子正文的电子邮件(帖子类型不是$post
, 但是$tribe_events
相反)每次都会更新,但仅针对该职位相关的员工。
为了获取电子邮件地址,我在$tribe_events
根据我在网上找到的添加社交媒体按钮的插件发布type editor,效果很好:
add_action( \'add_meta_boxes\', \'add_custom_box\' );
function add_custom_box( $tribe_events ) {
add_meta_box(
\'animateurs\', // ID, should be a string.
\'Animateurs\', // Meta Box Title.
\'social_services\', // Your call back function, this is where your form field will go.
\'tribe_events\', // The post type you want this to show up on, can be post, page, or custom post type.
\'side\', // The placement of your meta box, can be normal or side.
\'core\' // The priority in which this will be displayed.
);
}
function social_services( $tribe_events )
{
// Get post meta value using the key from our save function in the second paramater.
$custom = get_post_meta($tribe_events->ID, \'_social_services\', true);
?>
<input type="checkbox" id="anim_patrick" name="social_services[]" value="patrick@example.com" <?php echo (in_array(\'patrick@example.com\', $custom)) ? \'checked="checked"\' : \'\'; ?>>
<label for="anim_patrick"></label>Patrick<br>
<input type="checkbox" id="anim_jeff" name="social_services[]" value="jeff@example.com" <?php echo (in_array(\'jeff@example.com\', $custom)) ? \'checked="checked"\' : \'\'; ?>>
<label for="anim_jeff"></label>Jeff<br>
<?php
}
function save_extra_fields(){
global $post;
if(isset( $_POST[\'social_services\'] ))
{
$custom = $_POST[\'social_services\'];
$old_meta = get_post_meta($post->ID, \'_social_services\', true);
// Update post meta
if(!empty($old_meta)){
update_post_meta($post->ID, \'_social_services\', $custom);
} else {
add_post_meta($post->ID, \'_social_services\', $custom, true);
}
}
// update_post_meta($post->ID, "producers", $_POST["producers"]);
}
add_action( \'save_post\', \'save_extra_fields\' );
The result
这将成功保存活动帖子所涉及的员工的电子邮件地址。我可以使用此代码显示这些电子邮件地址的数组(在页面上-不是我想做的。这纯粹是为了显示如何从数组中获取电子邮件地址):
<?php $meta = get_post_meta($post->ID, \'_social_services\', true); $anims = implode (", ", $meta); echo $anims; ?>
我需要的是最后一部分,那就是向中包含的电子邮件地址发送一封包含最新帖子内容的电子邮件$anims
每次$tribe_events
职位类型已更新。我如何才能做到这一点?
PS:我是PHP的nube。这是我第一次尝试这样的事情。