Custom Field Display After Event Passed

Home Forums Calendar Products Events Calendar PRO Custom Field Display After Event Passed

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #529255
    Joshua
    Participant

    Hello. I have a custom field setup called “Tickets” which adds a URL to a button.

    How would I got about setting it up, so that after the event has passed, the custom field output no longer will display?

    Old events can remain archived but should not have the button display after event is over.

    #532443
    Barry
    Member

    Hi!

    The basis of this sort of change would be to override pro/modules/meta/additional-fields.php (more about the basics of this process can be found in our Themer’s Guide) and update your custom template to something like this:

    <?php
    if ( ! isset( $fields ) || empty( $fields ) || ! is_array( $fields ) ) return;
    $event_passed = tribe_get_end_date( null, false, 'Y-m-d H:i:s' ) < date( 'Y-m-d H:i:s' );
    ?>
    
    <div class="tribe-events-meta-group tribe-events-meta-group-other">
    	<h3 class="tribe-events-single-section-title"> <?php _e('Other', 'tribe-events-calendar' ) ?> </h3>
    	<dl>
    	<?php foreach ( $fields as $name => $value): ?>
            <?php if ( 'Button' === $name && $event_passed ) continue; ?>
    		<dt> <?php echo $name ?> </dt>
    		<dd class="tribe-meta-value"> <?php echo $value ?> </dd>
    	<?php endforeach ?>
    	</dl>
    </div>

    What should then happen, if the event has passed, is that the specified field will no longer be displayed. Of course, you’ll need to update this line:

    <?php if ( 'Button' === $name && $event_passed ) continue; ?>

    Changing Button to the actual field name applicable in your case.

    Does that help here?

    #533976
    Joshua
    Participant

    I guess I don’t understand how to work this out. I’ve done what you said and overwrote the code in the additional-fields.php file directly, changing ‘Button’ to the label of my custom field, ‘Tickets’ and nothing has changed. The button still appears on past events.

    If I understand your code correctly, you’re simply overriding the previous code and asking that if the custom field = ‘Button’, and the date is anytime from right now to a past time, echo $name.

    Here’s the code I’m using to make the button work on the front-end… I know I’m close, just not sure what I’m forgetting.


    " target="_blank">
    <button class="btn btn-default btn-tickets btn-lg col-xs-12">Buy Tickets</button>

    #533979
    Joshua
    Participant
    #533983
    Joshua
    Participant
    #533988
    Joshua
    Participant
    #533992
    Joshua
    Participant

    Sorry, please remove the old replies. Here’s a proper reply:
    http://jsfiddle.net/w7rtc/

    #540242
    Barry
    Member

    OK, I don’t really have the full context as you’ve only shared a small piece of your code – but am I right in thinking you are doing this from outwith the additional fields loop?

    Ultimately, something very similar is going to be needed. You need to determine if the event has passed or not and then – if a button URL has been set – display it.

    Can you simply borrow the line of code I used to set $event_passed and use that as a test before displaying your button code?

    #560857
    Joshua
    Participant

    Oh, boy! I’m not sure… I’ve created a new fiddle… the first section of commented code is from the additional-fields.php update, the 2nd section is from my custom single-event.php

    http://jsfiddle.net/6KLB4/

    #579642
    Barry
    Member
    <div class="well well-times">
        <p class="text-center">Show times may vary, <a href="<?php echo esc_url( tribe_get_custom_field( 'Tickets' ) ) ?>" target="_blank">Buy Tickets</a> to pick times.</p>
    </div>

    OK, so the button you’re trying to show/hide is represented by this section from your single-event.php template?

    Can you try changing wrapping that up something like this:

    <?php if ( ! $event_passed ): ?>
        <div class="well well-times">
            <p class="text-center">Show times may vary, <a href="<?php echo esc_url( tribe_get_custom_field( 'Tickets' ) ) ?>" target="_blank">Buy Tickets</a> to pick times.</p>
        </div>
    <?php endif ?>

    (Essentially, test to make sure the event hasn’t passed before printing it out) … does that help?

    #580747
    Joshua
    Participant

    That’s perfect. That’s exactly what I needed. Thanks!

    #580821
    Joshua
    Participant

    … and for clarification, additional-fields.php does not need to be adjusted to make this work. Just use the code above in the loop.

    #580875
    Joshua
    Participant

    Actually, this is working great on the single-event.php page from above, but doesn’t work in the loop for the /list/single-event.php page where I have other content I want removed if the event has passed.

    #587920
    Barry
    Member

    Actually, this is working great on the single-event.php page from above, but doesn’t work in the loop for the /list/single-event.php page where I have other content I want removed if the event has passed.

    It basically should work, but it’s very hard to assist without knowing what exactly you have tried. Certainly if I apply the same technique to list/single-event.php and hide the schedule details (the date and time) whenever an event has passed it works – the schedule details display on upcoming event pages but are hidden if I page back to past events.

     

    #589718
    Joshua
    Participant

    Here’s my code: http://pastebin.com/DwGBf6BF

    That’s from /list/single-event.php which is a template part included in the /list/loop.php, so I’d think it would behave the same as a single-event, but expired events still show the “Buy Tickets” button.

Viewing 15 posts - 1 through 15 (of 18 total)
  • The topic ‘Custom Field Display After Event Passed’ is closed to new replies.