functions – If ACF field is empty show different value

Question

I have a function setup in my functions.php file which I am trying to use to show a Advanced Custom Field with a fallback value if that field is empty. Here is what I have so far:

add_filter( 'facetwp_map_marker_args', function( $args, $post_id ) {

    $field = get_field( 'Type', $post_id ); // Get this post's ACF value
    $tent="tent"; 
    $value =   if( $field == true ){ echo $field;} else { echo $tent; };

    $args['icon'] = 'https://www.muddycamper.com/wp-content/themes/oceanwp-child-theme-muddy-camper/images/markers/' . $value . '.png';
 
  return $args; }, 10, 2 );

In other words:
If $field has a value then it should be use but if it is empty then it should default to $tent.

0
moorewebx 4 months 2022-01-25T19:48:35-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse