Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionI 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'] = '/' . $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.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionI 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.
Share Improve this question asked Jan 26, 2022 at 0:48 moorewebxmoorewebx 571 gold badge2 silver badges6 bronze badges 2 |1 Answer
Reset to default 2This is basically a php question.
add_filter( 'facetwp_map_marker_args', function( $args, $post_id ) {
$field = get_field( 'Type', $post_id ); // Get this post's ACF value
$tent = 'tent';
if( !$field ){
$field = $tent;
}
$args['icon'] = 'https://www.muddycamper.com/wp-content/themes/oceanwp-child-theme-muddy-camper/images/markers/' . $field . '.png';
return $args; }, 10, 2 );
You could do it your way as well, but it's extra coding:
add_filter( 'facetwp_map_marker_args', function( $args, $post_id ) {
$field = get_field( 'Type', $post_id ); // Get this post's ACF value
$tent = 'tent';
if( $field ){
$value = $field;
} else {
$value = $tent;
}
$args['icon'] = 'https://www.muddycamper.com/wp-content/themes/oceanwp-child-theme-muddy-camper/images/markers/' . $value . '.png';
return $args; }, 10, 2 );
$value = $field ? $field : $tent;
would do the logic you described. – Sally CJ Commented Jan 26, 2022 at 4:32