最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - get_post_meta not working on publishing

programmeradmin1浏览0评论

I'm building a notification system for a mobile app on Wordpress using One Signal.

Now Supposed to when I publish a new post sends a notification to all my Application devices.

The problem is I can't send post_meta with one signal notifications as it returns an undefined value first time when I hit the publish button.

But it works when I click update next time on the same post!! so why that delay/behavior?!

Same issue/behavior also with get_field for ACF plugin.

The code of the filter that one signal using:

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

function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
    // Change the notification's title, message, and URL
    if($post->post_type == "mobile_notifications"){
        $fields['headings'] = array("en" => wp_strip_all_tags($post->post_title));
        $fields['contents'] = array("en" => wp_strip_all_tags($post->post_content));

        $fields['data'] = array( 'type' => 'product', 'data' => get_post_meta( $post->ID, 'prefix_hash_product' ) );

//            if ( !empty(get_field('target_product', $post->ID)) ) {
//                $fields['data'] = array( 'type' => 'product', 'data' => get_field('target_product', $post->ID) );
//            } elseif(!empty(get_field('target_category', $post->ID))) {
//                $fields['data'] = array( 'type' => 'category', 'data' => get_field('target_category', $post->ID) );
//            }
    }
    unset($fields['url']);

    return $fields;
}
发布评论

评论列表(0)

  1. 暂无评论