• Resolved bk14165

    (@bk14165)


    I have used the following function in functions.php to show the attribute #_LATT{gomap-link} on the Location page only if the attribute is set:

    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Location){
        if (is_object($EM_Location)) {
     
            switch ($condition) {
     
                // replace LF with HTML line breaks
                case 'nl2br':
                    // remove conditional
                    $replacement = preg_replace('/\{\/?nl2br\}/', '', $match);
                    // process any placeholders and replace LF
                    $replacement = nl2br($EM_Location->output($replacement));
                    break;
     
                // #_ATT{gomap-link}
                case 'has_gomap-link':
                    if (is_array($EM_Location->location_attributes) && !empty($EM_Location->location_attributes['gomap-link']))
                        $replacement = preg_replace('/\{\/?has_gomap-link\}/', '', $match);
                    else
                        $replacement = '';
                    break;
            }
        }
        return $replacement;
    }
     
    add_filter('em_location_output_condition', 'filterLocationOutputCondition', 10, 4);

    Unfortunaltely it doesn’t do what i expected. I use the following code in the plugin settings (Formats/Locations):

    {has_gomap-link}<a href="#_LATT{gomap-link}">PokemonGoMap.info</a><br/>{/has_gomap-link}

    what is displayed as the result is any case:

    {has_gomap-link}PokemonGoMap.info
    {/has_gomap-link}

    Where is my mistake?
    Thank you in advance
    Burkhard

    • This topic was modified 6 years, 6 months ago by bk14165.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, EM User here too ??

    Personally I have always had problems with creating conditional placeholders with {}. So, I usually create a normal placeholder with an if/else condition. I tested this for you and it works:

    
    function my_em_placeholder_mod($replace, $EM_Location, $result){
    if ( $result == '#_GOMAP' ) {
    		if( !empty( $EM_Location->output("#_LATT{gomap-link}" ) ) ){
    			$replace = '<a href="#_LATT{gomap-link}">PokemonGoMap.info</a><br/>';
    		} 
    		else {
    			$replace = '';
    		}
    	}
    	return $replace;
    }
    add_filter('em_location_output_placeholder','my_em_placeholder_mod',1,3);
    

    Then just use #_GOMAP instead go the {has_gomap-link}… {/has_gomap-link}. The #_GOMAP placeholder will then check itself if he has to output anything ??

    Thread Starter bk14165

    (@bk14165)

    Hi Patrick,
    thank you very much. It worked for me but I had to write

    
    if ( $result == '#_GOMAP' ) {
    		if( !empty( $EM_Location->output("#_LATT{gomap-link}" ) ) ){
    			$replace = '<a href="' . $EM_Location->output("#_LATT{gomap-link}") . '">PokemonGoMap.info</a><br/>';;
    		} 
    		else {
    			$replace = '';
    		}
    

    Best regards
    Burkhard

    You’re welcome ??

    Ah, I guess that difference depends on where you use the placeholder. Your version is more “allround proof”, apparently. LOL. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with conditional placeholder for Location custom field’ is closed to new replies.