Conditionally display Additional Field, or customize Additional Field URL?

Home Forums Calendar Products Events Calendar PRO Conditionally display Additional Field, or customize Additional Field URL?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #943687
    Sean Sullivan
    Participant

    [Looked through previous related threads but couldn’t find an answer to my question.]

    I have a few Additional Fields in my events; they display in a custom-built Nivo Slider through WP_Query.

    The fields won’t always be used, and I’d only like them displayed when a value has been entered (e.g., there’s one for a Facebook link, one for a Buy Tickets link, etc.).

    I’d initially set the field as a “URL”. With a value of http://facebook.com, it outputs this HTML:

    <a target="self" href="http://facebook.com">http://facebook.com</a>

    The good: If no value is entered, nothing is displayed. The bad is that it doesn’t allow me to style the link or add a class. I’d prefer an output of:

    http://facebook.com

    … so I could wrap it in a <a> tag.

    So, I figured I’d just set the additional fields as Text. That gets me a plain value of http://facebook.com spit out. Here’s the code I’m using:

    <a class="slider-facebook-link" href="<?php $additional_fields = tribe_get_custom_fields(); echo $additional_fields['Facebook Event Link'];?>">Facebook</a>

    Is this the best way to achieve what I’d like? If so, how can I set a conditional to only display the field if it has a value?

    My attempt is:

    <?php if($additional_fields = tribe_get_custom_fields(['Facebook Event Link'])) { ?>
     <a class="slider-facebook-link" href="<?php $additional_fields = tribe_get_custom_fields(); echo $additional_fields['Facebook Event Link'];?>">Facebook</a>
    <?php } ?>

    “>Facebook

    #943688
    Sean Sullivan
    Participant

    Sorry, that first code block should have read:

    <a target="self" href="http://facebook.com">http://facebook.com</a>

    #943691
    Sean Sullivan
    Participant

    I’m not sure how I’m linking code wrong. Again, that first code block should be: http://facebook.com

    #943694
    Sean Sullivan
    Participant
    #943782
    Brian
    Member

    Hi,

    Thanks for using the Events Calendar. I can help out here.

    Best way to share code a lot of the time is through Pastebin (can do it without an account) or as a Gist.

    I think I got what you are trying to do.

    Try this instead:

    <?php
    $additional_fields = tribe_get_custom_fields();

    if ( $additional_fields['Facebook Event Link'] ) { ?>

    tribe_get_custom_fields() returns an array for all additional fields.

    Use that once then you can echo the value for any of your fields by adding the name:

    <?php echo $additional_fields['Facebook Event Link']; ?>

    Let me know if that works for you.

    Thanks

    #951907
    Brian
    Member

    Since there is has not been any activity on this thread for over 2 weeks so I am now closing it. Feel free to start a new thread if you have further issues. Thanks! 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Conditionally display Additional Field, or customize Additional Field URL?’ is closed to new replies.