我试图通过Wordpress插件发送推送通知,只有当我从给定类别发布时。但它没有用。
/ *添加新帖子时处理通知* /
function fcm_main_transition_post_new($new_status, $old_status, $post){
$catId = get_cat_ID();
if( $catId == 'Result'){
fcm_notif_post_new($new_status, $old_status, $post);
}
else{
echo "This category is not set to send push notification.";
}
}
答案 0 :(得分:0)
实际上$post
变量是什么?如果是from WordPress core,请使用以下代码:
$categories = get_the_category( $post->ID );
foreach( $categories as $category ) {
if( $category->cat_ID == 'Your category ID' ){
// Send notification please
}
// If you need category slug check
if( $category->cat_name == 'Your category slug' ){
// Send notification please
}
}
get_cat_ID()
返回一个整数,而不是Result
之类的字符串。