• markjenkins1981

    (@markjenkins1981)


    Hi there,

    I am using the following code to check if a custom field has a value and displaying a button if it does and a text string if it doesn’t.

    <?php
    $values = get_field( 'ticket_link' );
    if ( $values ) {
    echo '<a href="" class="button radius">Buy tickets</a>';
    } else {
    echo '<span class="no-tickets">Tickets not available yet</span>';
    }
    ?>

    The custom field ticket_link has a URL associated with it, which I’d like to use for the a href=”” but I am struggling to add this properly without breaking everything.

    Any help, much appreciated!

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter markjenkins1981

    (@markjenkins1981)

    I think I solved my own problem with:

    <?php
    $values = get_field( 'ticket_link' );
    if(get_field('ticket_link')) {
    echo '<a href="' . get_field('ticket_link') . '" class="button radius" target="_blank">Buy ticket</a>';
    } else {
    echo '<span class="no-tickets">Tickets not available yet</span>';
    }
    ?>
    ztig

    (@ztig)

    This should do it

    <?php
    $values = get_field( 'ticket_link' );
    if ( $values ) {
    echo '<a href=" '. $values . ' " class="button radius">Buy tickets</a>';
    } else {
    echo '<span class="no-tickets">Tickets not available yet</span>';
    }
    ?>
    Thread Starter markjenkins1981

    (@markjenkins1981)

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying custom field conditionally’ is closed to new replies.