Hello,
I have this code:
$image = get_field('banner_image', get_option('page_for_posts'))['url'];
if(empty($image)){
$image = get_template_directory_uri().'/assets/img/breadcrumb/breadcrumb-bg-1.jpg';
}
and getting on the first line the php notice:
“Trying to access array offset on value of type bool”
I hope the following solution might be the correct way??
I changed the first line to:
if (!empty($image)) {
$image = get_field('banner_image', get_option('page_for_posts'))['url'];
}
thanx in advance
The offset value notice did appear as long as the field “banner_image” is still empty.
My solution above was just to stop the notice.
Correct it should be like this, maybe somebody has a better way:
if (isset(get_field('banner_image', get_option('page_for_posts'))['url'])) {
$image = get_field('banner_image', get_option('page_for_posts'))['url'];
}
if(empty($image)){
$image = get_template_directory_uri().'/assets/img/breadcrumb/breadcrumb-bg-1.jpg';
}