Displaying custom field on single event

Home Forums Calendar Products Events Calendar PRO Displaying custom field on single event

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #961241
    mnussbaum
    Participant

    So 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!

    #961246
    mnussbaum
    Participant

    Quick 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>
    &nbsp;
    <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>
    #961334
    Brian
    Keymaster

    Hi,

    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

    #961338
    mnussbaum
    Participant

    Hey 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; ?>
    
    &nbsp;
    
    <?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; ?>
    #961341
    mnussbaum
    Participant

    Sorry, 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.

    #961342
    mnussbaum
    Participant

    Never mind, I seem to have resolved the issue myself! Thanks for the help, Brian!

    #961419
    Brian
    Keymaster

    I 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!

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Displaying custom field on single event’ is closed to new replies.