Support » Plugin: Events Manager » How to display custom attributes only when filled in?

  • Resolved zomigi


    I created a number of custom attributes for my events, and I have their content displaying on my events pages without a problem. However, not every event has every attribute filled in. How can I show the content of a custom attribute only when it is filled in, and otherwise show nothing?

    Right now, I’m using the Formatting setting area of EM to control what displays on my single event page. Here’s what that looks like:

    <span class="meta date">#F #j #@_{\&\n\d\a\s\h\;j}, #Y{has_location}, in #_LOCATIONNAME{/has_location}</span>
    <span class="meta">#_CATEGORYNAME:</span>
    <h2>"#_ATT{Session Title}"</h2>
    <ul class="list-simple">
    <li><a href="#_ATT{Follow-up Blog Post}">Get related resources</a></li>
    <li><a href="#_ATT{Slideshare URL}">View on Slideshare</a></li>
    <li><a href="#_ATT{Recording URL}">View recording</a></li>
    <li><a href="#_ATT{Conference Site}">Go to conference site</a></li>

    I’m not that skilled at PHP, so please be gentle in your reply. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • you need to create custom conditional placeholder for this, try this similar thread –

    *please see my sample snippet

    Thanks agelonwl, I tried it on one of my custom placeholders and it worked perfectly.

    Is there a way to modify the code to work with all four of my custom placeholders without having to copy that function multiple times? Just want to keep the code as DRY as possible. Thanks!

    yes, maybe adding new “if else conditions”


    if( is_object($EM_Event) && preg_match('/^has_venueurl$/',$condition, $matches) ){
    }else if( is_object($EM_Event) && preg_match('/^has_menuurl$/',$condition, $matches) ){
    }elseif( is_object($EM_Event) && preg_match('/^has_appleurl$/',$condition, $matches) ){

    Actually, I spoke too soon–it’s not working for me even with only one of the custom attributes in there. 🙁 It’s never showing the piece of data, even when the attribute does have some content in it.

    Here’s my function:

    function my_em_has_attribute_event_output_condition($replacement, $condition, $match, $EM_Event){
        if( is_object($EM_Event) && preg_match('/^has_slideshare$/',$condition, $matches) ){
        	if( !in_array($args['slideshare_url'],$EM_Event->event_attributes) && !empty($EM_Event->event_attributes['slideshare_url']) ){
                $replacement = preg_replace("/\{\/?$condition\}/", '', $match);
                $replacement = '';
        return $replacement;
    add_action('em_event_output_condition', 'my_em_has_attribute_event_output_condition', 1, 4);

    And then here’s how I’m using it:

    {has_slideshare}<li><a href="#_ATT{Slideshare URL}">View on Slideshare</a></li>{/has_slideshare}

    What am I doing wrong?

    could it because you are using slideshare_url instead of Slideshare URL (#_ATT{Slideshare URL}) ?

    Cool, I got it fixed, and got all four custom attributes working. The code is not at all DRY, but I’m not a programmer to fix it, so I’ll have to live with it! 🙂

    Thanks very much for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to display custom attributes only when filled in?’ is closed to new replies.