Creating a Button/Text Link for a Custom Field

Home Forums Calendar Products Events Calendar PRO Creating a Button/Text Link for a Custom Field

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #994815
    Heather Wood
    Participant

    Hi, I noticed this article which is cool and tells me how to create a text link from the website URL
    https://theeventscalendar.com/knowledgebase/url-as-word-button/

    My question is, I created a custom field URL named Syllabus. How would I know what the filer is called so I can modify this code to do the same thing, but for my custom field?

    //Create button from Syllabus in The events calander
    add_filter(‘tribe_get_event_website_link_label’, ‘tribe_get_event_website_link_label_default’);

    function tribe_get_event_website_link_label_default ($label) {
    if( $label == tribe_get_event_website_url() ) {
    $label = “Visit Website »”;
    }

    return ‘‘ . $label . ‘ ‘;
    }

    #994831
    George
    Participant

    Sorry Heather, we unfortunately don’t offer support for custom code here on the forums so I will have to close up this thread pretty soon…

    However, just to try and shed some light on things before closing the thread, if you’re using a separate custom field that you’re trying to display there, then you will need to use the WordPress function get_post_meta() and call that field directly, not just use the tribe_get_event_website_url() function.

    An alternative to all of this is to use an Events Calendar Pro “Additional Field” to store that Syllabus information, and you can then quite easily get this to show in that event meta section. You can learn about this alternative method here → https://theeventscalendar.com/knowledgebase/pro-additional-fields/

    Cheers,
    George

    #994841
    Heather Wood
    Participant

    that’s actually exactly what I’m asking.

    I already created my custom field using this method

    Creating Additional Fields

    so how would I know what the filter is? by using the get method?
    what is generated when I create the field…?

    #995204
    George
    Participant

    Hey Heather,

    Awesome, in that case then yes retrieving the data is as simple as using a function called tribe_get_custom_fields().

    If your custom field’s name is just “Syllabus”, for example, then code like this would work to echo the value of that field for a given event:


    $custom_fields = tribe_get_custom_fields();

    echo $custom_fields['syllabus'];

    So, the original code example you posted was this:

    add_filter('tribe_get_event_website_link_label', 'tribe_get_event_website_link_label_default');

    function tribe_get_event_website_link_label_default ($label) {
    if( $label == tribe_get_event_website_url() ) {
    $label = "Visit Website »";
    }

    return '' . $label . ' ';
    }

    And example of reworking that to use the new field is this:


    add_filter('tribe_get_event_website_link_label', 'tribe_get_event_website_link_label_default');

    function tribe_get_event_website_link_label_default ($label) {

    $custom_fields = tribe_get_custom_fields();

    if( isset( $custom_fields['syllabus'] ) && $label == $custom_fields['syllabus'] ) {
    $label = "Visit Website »";
    }

    return '' . $label . ' ';
    }

    That should help – we unfortunately can’t provide much more code-level support than snippets like this, but play around with things a bit and let us know if it helps.

    Best of luck with your customizing,
    George

    #999124
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Creating a Button/Text Link for a Custom Field’ is closed to new replies.