Home › Forums › Calendar Products › Events Calendar PRO › Custom Field Display After Event Passed
- This topic has 17 replies, 2 voices, and was last updated 11 years, 8 months ago by
Barry.
-
AuthorPosts
-
July 28, 2014 at 6:58 pm #529255
Joshua
ParticipantHello. 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.
July 29, 2014 at 6:26 am #532443Barry
MemberHi!
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?
July 29, 2014 at 12:21 pm #533976Joshua
ParticipantI 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>
July 29, 2014 at 12:22 pm #533979Joshua
ParticipantJuly 29, 2014 at 12:22 pm #533983Joshua
ParticipantHaving trouble pasting code properly.
” target=”_blank”>
<button class=”btn btn-default btn-tickets btn-lg col-xs-12″>Buy Tickets</button>July 29, 2014 at 12:24 pm #533988Joshua
ParticipantJuly 29, 2014 at 12:25 pm #533992Joshua
ParticipantSorry, please remove the old replies. Here’s a proper reply:
http://jsfiddle.net/w7rtc/July 30, 2014 at 9:15 am #540242Barry
MemberOK, 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?
August 1, 2014 at 4:52 pm #560857Joshua
ParticipantOh, 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
August 4, 2014 at 10:55 am #579642Barry
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?
August 4, 2014 at 1:59 pm #580747Joshua
ParticipantThat’s perfect. That’s exactly what I needed. Thanks!
August 4, 2014 at 2:12 pm #580821Joshua
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.
August 4, 2014 at 2:24 pm #580875Joshua
ParticipantActually, 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.
August 5, 2014 at 7:41 am #587920Barry
MemberActually, 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.
August 5, 2014 at 12:56 pm #589718Joshua
ParticipantHere’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.
-
AuthorPosts
- The topic ‘Custom Field Display After Event Passed’ is closed to new replies.
