• Resolved davidjs

    (@davidjs)


    While viewing the default list view I want to show the event link field wrapped in button html which will link to the external event url. Just like here https://www.nascar.com/nascar-cup-series/2022/schedule/#
    I just want to say (buy tickets).
    There does not appear to be clear documentation on how to add a field to the event edit page below the event link field, and I dont see documentation for displaying a custom field on the list view. I dont want my custom fields to show up on single view in a “other section” like the pro plugin has.

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

    (@davidjs)

    just for the link potion of the button I tried to use $website_title = tribe_events_get_event_website_title(); <?php echo $website; ?>
    But this produces the text of the link then linked to itself. I cant use that in a <ahref>

    So I need two custom fields, one for the button text and one for the button link and I need a way to drop that into the list view. Im thinking of editing the featured-image.php in my child theme and dropping the button in there.

    I dont think there are filters/action hooks in the list view so documentation I found for adding fields to the event manager or venue wont work.

    • This reply was modified 3 years, 2 months ago by davidjs.
    Thread Starter davidjs

    (@davidjs)

    This assumes you have the pro plugin. I do not know how to create custom files otherwise. You can paste this right into the template file you edit in the child theme or create a
    new file for this and call it with a function.

    ———————————————-
    Put this code in functions file

    add_action( 'tribe_template_after_include:events/v2/list/event/featured-image',
      function ( $file, $name, $template ) {
        $template->template( 'list/event/tooltip-extra-fields' );
      }, 
    10, 
    3 
    );

    ————————————————————————————-
    Put this code in featured-image.php for example or in its own file like tooltip-extra-fields.php

    <?php
    // Get the event ID.
    $event_id = get_the_ID();

    // Fetch from this Event all custom fields and their values.
    $fields = tribe_get_custom_fields( $event_id );
    ?>

    <div class=”theme-extra-event-fields”>
    <?php if ( ! empty( $fields[‘Button Text’] ) ) : ?>
    <h4>Artist</h4>
    <p>
    <?php if ( ! empty( $fields[‘Ticket Link’] ) ) : ?>
    ” target=”_blank”>
    <?php endif; ?>
    <?php echo esc_html( $fields[‘Button Text’] ); ?>
    <?php if ( ! empty( $fields[‘Ticket Link’] ) ) : ?>

    <?php endif; ?>
    </p>
    <?php endif; ?>
    </div>

    @davidjs

    Thank you for sharing your solutions so that others can benefit from it!

    While on that topic, just a small caveat, functions.php might not be the best cases in most cases. You can read about it here: https://wpmudev.com/blog/why-you-shouldnt-use-functions-php/

    As a result, these days most people use a plugin such as the following instead:

    1. https://wordpress.org/plugins/my-custom-functions/
    2. https://wordpress.org/plugins/code-snippets/

    Cheers,
    Geoff

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add Custom Field to the List View’ is closed to new replies.