• Resolved antwoorden

    (@antwoorden)


    I want to create another custom conditional: has_region.
    But somehow I can’t manage to get it right…

    This is what I tried in my theme’s functions.php, but didn’t work:

    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Location){
    if (is_object($EM_Location)) {

    switch ($condition) {

    case ‘has_region’:
    if (is_array($EM_Location->location_attributes) && !empty($EM_Location->location_attributes[‘Region’]))
    $replacement = preg_replace(‘/\{\/?has_region\}/’, ”, $match);
    else
    $replacement = ”;
    break;

    }

    }

    return $replacement;
    }

    add_filter(’em_location_output_condition’, ‘filterLocationOutputCondition’, 10, 4);

    https://www.ads-software.com/extend/plugins/events-manager/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    can you try this?

    add_action('em_location_output_condition', 'filterLocationOutputCondition', 1, 4);
    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Location){
    	if( is_object($EM_Location) && preg_match('/^has_region/',$condition, $matches) ){
    		if ( is_array($EM_Location->location_attributes) && !empty($EM_Location->location_attributes['Region']) ){
    			$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
    		}else{
    			$replacement = '';
    		}
    	}
    	return $replacement;
    }
    Thread Starter antwoorden

    (@antwoorden)

    Thanks for your effort! But it doesn’t work…

    I placed your code in functions.php of Twenty Twelve (theme I’m using on this test). I put something between {has_region} and {/has_region} at the single location markup, but still no result: the conditional phrase doesn’t appear, while the locations do have regions…

    Thread Starter antwoorden

    (@antwoorden)

    In other words: it always gives the else replacement, as if no location has a defined region…

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    i think there’s a mistake in the above code:

    add_action('em_location_output_condition', 'filterLocationOutputCondition', 1, 4);
    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Location){
    	if( is_object($EM_Location) && preg_match('/^has_region/',$condition, $matches) ){
    		if ( is_array($EM_Location->location_region) && !empty($EM_Location->location_region) ){
    			$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
    		}else{
    			$replacement = '';
    		}
    	}
    	return $replacement;
    }
    Thread Starter antwoorden

    (@antwoorden)

    Thanks, but nope… same outcome.

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    another correction:

    add_action('em_location_output_condition', 'filterLocationOutputCondition', 1, 4);
    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Location){
    	if( is_object($EM_Location) && preg_match('/^has_region/',$condition, $matches) ){
    		if ( !empty($EM_Location->location_region) ){
    			$replacement = preg_replace("/\{\/?$condition\}/", '', $match);
    		}else{
    			$replacement = '';
    		}
    	}
    	return $replacement;
    }
    Thread Starter antwoorden

    (@antwoorden)

    This works great! Thank you VERY much!!!

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    yay ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Conditional: has_region’ is closed to new replies.