0
votes

I am creating a PWA in WordPress, and I would like to send notifications to user segments using the different categories of posts. I have consulted the Onesignal guide here. I created the segments based on the tags, using the slug of the post WordPress categories.

I installed the OneSignal plugin and followed the suggestions of this solution.

The form works correctly, segmenting users into users based on the category of their choice. I can not however make the sending of notifications work when a post of a certain category is sent, indeed adding in the functions.php the suggested code (see the attached code) is no longer sent any notification.

Where am I doing wrong?

I apologize for my uncertain English and I thank those who will pay attention to my question. Thank you and greetings

/**
* 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;
}

Adding this code to the functions.php of my child theme no notification is more sent by OneSignal

1

1 Answers

1
votes

your segments name must be same as your categories name

example; if you have category name "News" you should have segment "News" also