WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Conditional Placeholder with Custom Attributes (5 posts)

  1. Balders
    Member
    Posted 1 year ago #

    Hi there,

    I put the following code in the themes functions.php

    /**
    * add some conditional output conditions for Events Manager
    * @param string $replacement
    * @param string $condition
    * @param string $match
    * @param object $EM_Event
    * @return string
    */
    function filterEventOutputCondition($replacement, $condition, $match, $EM_Event){
        if (is_object($EM_Event)) {
    
            switch ($condition) {
    
                // replace LF with HTML line breaks
                case 'nl2br':
                    $replacement = nl2br(preg_replace('/\{\/?nl2br\}/', '', $match));
                    break;
    
                // #_ATT{Homepage}
                case 'has_att_homepage':
                    if (is_array($EM_Event->event_attributes) && !empty($EM_Event->event_attributes['Homepage']))
                        $replacement = preg_replace('/\{\/?has_att_homepage\}/', '', $match);
                    else
                        $replacement = '';
                    break;
    
            }
    
        }
    
        return $replacement;
    }
    
    add_filter('em_event_output_condition', 'filterEventOutputCondition', 10, 4);

    And the following in Formatting > Events > Single Events

    {has_att_website}
    Text
    {/has_att_website}

    I would like to hide the Custom Attribute #_ATT{Website} when it's empty. But it's gone anyway even if there is a url in there.

    Any thoughts?

    Cheers
    `

    http://wordpress.org/extend/plugins/events-manager/

  2. agelonwl
    Member
    Posted 1 year ago #

    Hi,

    you should be using {has_att_homepage}...{/has_att_homepage} instead.

  3. Balders
    Member
    Posted 1 year ago #

    Sorry, wrongly copied. I do use {has_att_homepage}

    As I said: The whole Attribute is gone, not just the one without url

    Any further thoughts?

    Cheers

  4. Balders
    Member
    Posted 1 year ago #

    SOLVED

    I nested the {has_att_homepage} within the {has_location} condition.

    Sorry for bothering you.

    Cheers again

  5. agelonwl
    Member
    Posted 1 year ago #

    This line !empty($EM_Event->event_attributes['Homepage']) try to replace with !empty($EM_Event->event_attributes['Website']) based on your events attribute #_ATT{Website} or try this similar thread http://wordpress.org/support/topic/plugin-events-manager-custom-conditional-placeholder-not-working?replies=12

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.