Cannot Change “No Events Found” Notice

Home Forums Calendar Products Events Calendar PRO Cannot Change “No Events Found” Notice

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1124230
    reelrock
    Participant

    Hi again,

    I’ve been trying to change the notice that is shown when no events are found using the search criteria (see screenshot). We have disabled all but the geolocation search, and only want to search by City/Zip (which is indicated in the search field).

    I would like the error message that comes up to say, “There were no events found. Please try your search again with City name or Zip Code.”

    I’ve seen a proposed solution using a string replacement function, but that doesn’t work here (I’m guessing because the notice that gets generated changes based on the search term input). The other option involved using filters but I didn’t understand how to apply it.

    Thanks for you help.

    #1124494
    Nico
    Member

    Hi there @reelrock,

    Thanks for reaching out to us! I can help you here…

    To change the no results text you can add the following snippet to your theme (or child theme) functions.php file:


    /* Modify the event-search-no-results notice text */
    add_filter( 'tribe_the_notices', function( $html, $notices ) {

    if ( empty( $notices ) || ! is_array( $notices ) ) return $html;

    if ( isset( $notices[ 'event-search-no-results' ] ) ) {
    $notices[ 'event-search-no-results' ] = 'There were no events found. Please try your search again with City name or Zip Code.';

    return sprintf( '

    • %s

    ', implode( '

  • ', $notices ) );
    }
    return $html;
    }, 10, 2 );
  • Please give this a try and let me know about it,
    Best,
    Nico

#1124687
reelrock
Participant

Awesome, thank you!

Would it be too much trouble to walk me through how this is working? I’ve been doing my best to learn all the ins and outs of your excellently designed plugins, and that has been a great way to learn PHP at a more advanced level, and I anticipate supporting this client for a while. If you don’t have the time, no worries.

Thanks again,
Khaled

#1125019
Nico
Member

Glad to hear this worked Khaled!

Also stocked to hear you are trying to learn more about our plugins 🙂

In this case we are using a filter (basically a way of changing the value of a variable without touching the wp or plugin core files – more about this here) to modify the notice output. The code inside the function is specific to how the notices are stored, filtering other values might be as simple as returning a value and that’s it.

Other way of doing the same thing would be to change the default translation string for a custom string:

/*
* Custom theme text: https://theeventscalendar.com/knowledgebase/change-the-wording-of-any-bit-of-text-or-string/
*/
function tribe_custom_theme_text ( $translations, $text, $domain ) {

$custom_text = array(
'No results were found for %1$s in or near %2$s.' => 'There were no events found. Please try your search again with City name or Zip Code.',
);

if((strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($text, $custom_text) ) {
$text = $custom_text[$text];
}

return $text;
}
add_filter('gettext', 'tribe_custom_theme_text', 20, 3);

Hope that helps to give you an idea of how this works!

Please let me know if you have any follow-up questions,

Best,
Nico

#1131895
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 ‘Cannot Change “No Events Found” Notice’ is closed to new replies.