Location part of Tribe Events Bar

Home Forums Calendar Products Events Calendar PRO Location part of Tribe Events Bar

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1198237
    Sally Newcomb
    Participant

    Using answers in other threads, I’ve nearly got this sorted, but can’t quite get it.

    I’m trying to do 2 things:
    1. Change the place holder text below the label near to: Enter Your Postcode (because this is a UK based website)
    2. Add the word ‘miles’ after the number of miles returned by the location search.

    Regards 1. – I have manage to change the label, but it then prevents ‘search by location’ from working??

    I’ve added the following to my functions file but changing the placeholder text to ‘Enter your Postcode’ for some reason stops the location search from working (when I removed the code from the functions.php it worked fine except the word miles still didn’t appear. What ever I put in the search box at the moment returns all events.

    /*
    * Change labels in Tribe events bar filter
    */

    add_filter( ‘tribe-events-bar-filters’, ‘tribe_support_1043886’ );

    function tribe_support_1043886( $filters ) {

    $value = ”;

    if ( ! empty( $_REQUEST[‘tribe-bar-search’] ) ) {
    $value = esc_attr( $_REQUEST[‘tribe-bar-search’] );
    }

    $html = sprintf(
    ‘<input type=”text” name=”tribe-bar-geoloc” id=”tribe-bar-geoloc” value=”%s” placeholder=”%s”>’,
    esc_attr( $value ),
    ‘Enter Your Postcode’
    );

    $filters[‘tribe-bar-geoloc’][‘caption’] = ‘Near’;
    $filters[‘tribe-bar-geoloc’][‘html’] = $html;

    return $filters;
    }

    /*
    * Change default distance label in Map View
    */
    add_filter( ‘tribe_get_distance_with_unit’, ‘tribe_custom_distance_label’, 10, 3 );

    function tribe_custom_distance_label ( $distance, $distance_in_kms, $unit ) {
    return ‘Distance From Location: ‘ . $distance . ‘ ‘ . $unit;
    }

    #1198700
    Cliff
    Member

    Hi Sally.

    1)

    The “Near” text is from Line 263 of /wp-content/plugins/events-calendar-pro/src/Tribe/Geo_Loc.php and can be changed via the code snippet at the bottom of https://theeventscalendar.com/knowledgebase/change-the-wording-of-any-bit-of-text-or-string/

    2)

    Go to wp-admin > Events > Settings > General tab > Map Settings section and change “Distance unit” from Miles to Kilometers

    #1198716
    Sally Newcomb
    Participant

    Go to wp-admin > Events > Settings > General tab > Map Settings section and change “Distance unit” from Miles to Kilometers

    I had already done that and it was already set to kilometres but still doesn’t work. In fact, I want it set to miles, not kilometres….. Should this work?:

    /*
    * Change default distance label in Map View
    */
    add_filter( ‘tribe_get_distance_with_unit’, ‘tribe_custom_distance_label’, 10, 3 );

    function tribe_custom_distance_label ( $distance, $distance_in_miles, $unit ) {
    return ‘Distance From Location: ‘ . $distance . ‘ ‘ . $unit;
    }

    If I add this to my functions.php, I just get a white screen:
    $custom_text = array(
    ‘Venue’ => ‘Location’,
    ‘Related %s’ => ‘Similar %s’,
    );

    #1198763
    Cliff
    Member

    I see from your System Information (that you provided on-demand access to), that geoloc_default_unit = miles, so, yes, you do have that setting to “Miles” instead of “Kilometers”.

    Could you please provide an annotated screenshot demonstrating the issue, along with a link to view an example event this is happening at?

    Additionally, your code snippet looks incomplete. Please make sure you’re using the code snippet at the very bottom of that KB article.

    Thank you.

    #1205120
    Sally Newcomb
    Participant

    This reply is private.

    #1205244
    Cliff
    Member

    This reply is private.

    #1205253
    Sally Newcomb
    Participant

    This reply is private.

    #1205660
    Cliff
    Member

    Got it. Thanks.

    That is coming from tribe_event_distance(), which is used in /wp-content/plugins/events-calendar-pro/src/views/pro/map/single-event.php

    You can use the Themer’s Guide to override that file to insert ” miles” or whatever you choose.

    Please let me know if this answers your question.

    #1206321
    Sally Newcomb
    Participant

    I’ve followed the steps in the Themer’s Guide which results in this path: /devdocs/wp-content/themes/dynamik-gen/tribe-events/pro/map/single-event.php

    I hoped it would be as simple as adding Miles like below, but although the word Miles appears, it isn’t displayed in the same class and it shows even when user hasn’t searched for distance from location.

    <!– Event Distance –>
    <?php echo tribe_event_distance(); ?>
    <span class=“tribe-events-distance”>Miles</span>

    What have I left out? Reading this thread, it looks like there’s more to do than just adding a word? https://theeventscalendar.com/support/forums/topic/describe-miles-after-search-result/

    #1206522
    Cliff
    Member

    tribe_event_distance() uses tribe_get_distance_with_unit(), which is able to be filtered with tribe_get_distance_with_unit

    So you could accomplish what you want 1 of 2 ways:

    1)

    Use the tribe_get_distance_with_unit filter, which may affect output elsewhere on your site.

    https://theeventscalendar.com/tips-working-wordpress-actions-filters/ is a helpful reference.

    2)

    Do a template override to replace this:

    <?php echo tribe_event_distance(); ?>

    with this:

    <?php
    $distance = tribe_event_distance();
    if ( ! empty ( $distance ) ) {
    echo str_replace( '</span>', ' Miles</span>', $distance );
    }
    ?>

    I hope this helps.

    #1206944
    Sally Newcomb
    Participant

    The template override worked perfectly, thank you so much!

    #1207139
    Cliff
    Member

    You bet! 🙂

    #1558251
    Victor
    Keymaster

    Hi There!

    Just wanted to share with you that a new release of our plugins is out, including a fix for this issue 🙂

    Find out more about this release → https://theeventscalendar.com/maintenance-release-week-17-june-2018/

    We apologize for the delay and appreciate your patience while we worked on this.

    Please update the plugins and see if the fix works for your site. Don’t hesitate to open a new topic if anything comes up.

    Best,
    Victor

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Location part of Tribe Events Bar’ is closed to new replies.