get_field with ID is not working in functions.php wordpress

I am trying to get_field() data using post id in functions.php file, I am getting the value of post id. But for some reason title and image values are null. I have imported wp-load, but still didn’t get the values. Can someone help me regarding this ?

require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-load.php’ );
add_filter(‘onesignal_send_notification’, ‘onesignal_send_notification_filter’, 10, 4);

function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
$current_affairs = get_field(‘current_affairs’,$post->ID);
$title = $current_affairs[0][‘headline’];
$image = $current_affairs[0][‘image’];
$fields[‘isAndroid’] = true;
$fields[‘isIos’] = true;
$fields[‘isAnyWeb’] = false;
$fields[‘isChrome’] = false;
$fields[‘data’] = array(
“id” => $id,
“headline”=> $title,
“image”=> $image,
“type” => “news”,
“news_data” => $current_affairs
);
/* Unset the URL to prevent opening the browser when the notification is clicked */
unset($fields[‘url’]);
return $fields;
}

Read more here:: get_field with ID is not working in functions.php wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *