Home › Forums › Calendar Products › Events Calendar PRO › Cannot Change “No Events Found” Notice
- This topic has 5 replies, 4 voices, and was last updated 9 years, 10 months ago by
reelrock.
-
AuthorPosts
-
June 8, 2016 at 5:35 pm #1124230
reelrock
ParticipantHi 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.
June 9, 2016 at 8:17 am #1124494Nico
MemberHi 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,
NicoJune 9, 2016 at 11:33 am #1124687reelrock
ParticipantAwesome, 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,
KhaledJune 10, 2016 at 6:21 am #1125019Nico
MemberGlad 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,
NicoJune 25, 2016 at 9:35 am #1131895Support Droid
KeymasterThis 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. -
AuthorPosts
- The topic ‘Cannot Change “No Events Found” Notice’ is closed to new replies.
