Shorthand Ternary Operators in PHP
Kevin Beck
—December 10, 2019
At Multiple States we use the ACF plugin with Wordpress and sometimes need to set a fallback for fields. Rather than a long If / Else statement we can use a Ternary Operator and to make it even easier we can use the shorthand:
$title = get_field(’title’) ?: ‘Fallback’;
Thanks to Chris Corby for this one.