【问题标题】:How to send notifications from OneSignal to segment users in WordPress?如何从 OneSignal 发送通知以在 WordPress 中细分用户?
【发布时间】:2019-01-06 09:43:28
【问题描述】:

我正在 WordPress 中创建 PWA,我想使用不同类别的帖子向用户群发送通知。我已经咨询了 Onesignal guide here。 我使用帖子 WordPress 类别的 slug 基于标签创建了细分。

我安装了OneSignal插件,并按照this solution的建议。

表单可以正常工作,根据用户选择的类别将用户划分为用户。但是,当发送某个类别的帖子时,我无法发送通知,实际上在functions.php 中添加建议的代码(请参阅附件代码)不再发送任何通知。

我哪里做错了?

对于我不确定的英语,我深表歉意,我感谢那些关注我问题的人。 谢谢和问候

/**
* Send notifications based on category, Onesignal
*/

add_filter('onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4);

function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
    $categories = get_the_category($post->ID);

    // Change which segment the notification goes to, will always be the first category
    $fields['included_segments'] = array($categories[0]->name);
    return $fields;
}

将此代码添加到我的子主题的functions.php 中,OneSignal 不会发送更多通知

【问题讨论】:

    标签: wordpress onesignal


    【解决方案1】:

    您的细分名称必须与您的类别名称相同

    示例; 如果您有类别名称“新闻”,您也应该有“新闻”部分

    【讨论】:

    • 有效!非常感谢!我错了,因为我没有用相同的类别名称来表示细分,而是用 slug !再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    相关资源
    最近更新 更多