I am editing a Wordpress theme and want to output a value that's inside an array in the post meta array.
My code is:
$banner_subtitle = get_post_meta( $post_id, 'header_section_meta', true );
echo print_r($banner_subtitle);
And my output is:
Array
(
[section_mode] => banner
[header_section_id] =>
[slider_alias] =>
[banner_subtitle] => SUBTITLE 1
[banner_image] => .jpg
[is_banner_image_parallax] => 0
[banner_image_repeat] => repeat-x
[banner_mask] =>
)
1
How can I modify my code so that the output is the value of the banner_subtitle, in this case "SUBTITLE 1", instead of that whole array? Thank you.
I am editing a Wordpress theme and want to output a value that's inside an array in the post meta array.
My code is:
$banner_subtitle = get_post_meta( $post_id, 'header_section_meta', true );
echo print_r($banner_subtitle);
And my output is:
Array
(
[section_mode] => banner
[header_section_id] =>
[slider_alias] =>
[banner_subtitle] => SUBTITLE 1
[banner_image] => http://www.example/image.jpg
[is_banner_image_parallax] => 0
[banner_image_repeat] => repeat-x
[banner_mask] =>
)
1
How can I modify my code so that the output is the value of the banner_subtitle, in this case "SUBTITLE 1", instead of that whole array? Thank you.
$banner_subtitle = get_post_meta( $post_id, 'header_section_meta', true );
if (!empty($banner_subtitle['banner_subtitle'])) {
echo $banner_subtitle['banner_subtitle'];
}
or as a ternary
$banner_subtitle = get_post_meta( $post_id, 'header_section_meta', true );
echo !empty($banner_subtitle['banner_subtitle']) ? $banner_subtitle['banner_subtitle'] : '';