Home › Forums › Calendar Products › Events Calendar PRO › Displaying custom field on single event
- This topic has 6 replies, 2 voices, and was last updated 11 years ago by
Brian.
-
AuthorPosts
-
May 7, 2015 at 10:53 am #961241
mnussbaum
ParticipantSo after searching the forums for a few hours this morning, I finally figured out how to create a button next to the price of an event to buy tickets and link that button to a custom field I added.
The code I used for this was:
<a class="fasc-button fasc-size-xsmall fasc-type-flat" style="background-color: #cccccc; color: #000000;" href="<?php echo esc_url( tribe_get_custom_field( 'Tickets' ) ) ?>" target="_blank" data-fasc-style="background-color:#cccccc;color:#000000;">Buy Tickets</a>My question is this: what kind of if statement can I enclose this in so if there is no value for the ‘Tickets’ custom field it won’t display the button. At the moment a button displays linking to the current page.
Thanks!
May 7, 2015 at 11:00 am #961246mnussbaum
ParticipantQuick update to my question that may change the answer:
I am using 2 custom fields, one called Tickets and one called Contest.
Each one creates a button, one that says Buy Tickets and one that says Enter to Win.
I need each of them to have individual if statements to determine if their respective values exist.
Thanks!
<strong><a class="fasc-button fasc-size-xsmall fasc-type-flat" style="background-color: #cccccc; color: #000000;" href="<?php echo esc_url( tribe_get_custom_field( 'Tickets' ) ) ?>" target="_blank" data-fasc-style="background-color:#cccccc;color:#000000;">Buy Tickets</a></strong> <strong><a class="fasc-button fasc-size-xsmall fasc-type-flat" style="background-color: #cccccc; color: #000000;" href="<?php echo esc_url( tribe_get_custom_field( ‘Contest’ ) ) ?>" target="_blank" data-fasc-style="background-color:#cccccc;color:#000000;">Enter to Win</a></strong>May 7, 2015 at 5:16 pm #961334Brian
MemberHi,
Thanks for using our plugins. I can help out here.
You maybe to you this to check for a value:
if ( tribe_get_custom_field( 'Tickets' ) ) { ?>
//Add coding here
<?php {Let me know how that works out.
Thanks
May 7, 2015 at 5:25 pm #961338mnussbaum
ParticipantHey Brian, thanks for the response!
I actually tried another more complicated method that worked for part of what I was trying to do but I’ll try that one as it’s less code.
I am having an issue however, and it is hopefully an easy fix. I have two additional fields I need to pull in for this. One is called Tickets and one is called Contest. The code below works perfectly for the ticket field, but it does not pull in the data for the contest field. Can you take a look and see what I might need to do to get the data from both fields so I can check that they are not null and create a button for each one that exists?
Thanks!
$ticketurl = esc_url( tribe_get_custom_field( 'Tickets' ) ); $contesturl = esc_url( tribe_get_custom_field( ‘Contest’ ) );<?php if ($ticketurl != null): ?> <span class="tribe-events-divider">|</span> <span class="tribe-events-cost"> <strong><a class="fasc-button fasc-size-xsmall fasc-type-flat" style="background-color: #cccccc; color: #000000;" href="<?php echo $ticketurl ?>" target="_blank" data-fasc-style="background-color:#cccccc;color:#000000;">Get Tickets</a></strong> <?php endif; ?> <?php if ($contest != null): ?> <span class="tribe-events-divider">|</span> <span class="tribe-events-cost"> <strong><a class="fasc-button fasc-size-xsmall fasc-type-flat" style="background-color: #cccccc; color: #000000;" href="<?php echo $contest ) ) ?>" target="_blank" data-fasc-style="background-color:#cccccc;color:#000000;">Enter to Win</a></strong></span> <?php endif; ?>May 7, 2015 at 5:29 pm #961341mnussbaum
ParticipantSorry, I was editing a couple of things and didn’t c/p the correct code. The $contest in the bottom set of code should be $contesturl.
May 7, 2015 at 5:34 pm #961342mnussbaum
ParticipantNever mind, I seem to have resolved the issue myself! Thanks for the help, Brian!
May 8, 2015 at 4:56 am #961419Brian
MemberI am glad to see you were able to figure it out.
I am going to go ahead and close this ticket. If you have a similar issue or another in the future, please do not hesitate to create a new ticket.
Thanks!
-
AuthorPosts
- The topic ‘Displaying custom field on single event’ is closed to new replies.
