Search not working with [events_list]
-
I have the following shortcode which does not show the search:
[events_list full="1" has_search="1" sorting="0" show_advanced="0" search_geo="0" show_search="1" long_events="1"]
However right above I have this shortcode which works fine and shows the search:
[events_calendar full="1" has_search="1" sorting="0" show_advanced="1" search_geo="0" show_search="1" long_events="1"]
Is this a bug? According to the documentation, the [events_list] should also support all search parameters ??
-
Yes, I believe this is a bug. Here’s a hack to do what you want (definitely not ideal).
First create the directory wp-content/plugin-templates/events-manager/templates and then create a file in that directory called events-search.php with the following content:
<script>
jQuery(document).ready( function($){
$(window).on('load', function() {
$('.em-search-submit').click();
});
});
</script>
<?php
/* @var $args array */
$args['sorting'] = 0;
$args['long_events'] = 1;
$args['full'] = 1;
$args['search_geo'] = 0;
$args['show_advanced'] = 0;
$args['search_action'] = 'search_events';
$args['search_url'] = get_option('dbem_events_page') ? get_permalink(get_option('dbem_events_page')):EM_URI;
$args['css_classes'][] = 'em-events-search';
$args['css_classes_advanced'][] = 'em-events-search-advanced';
em_locate_template('templates/search.php', true, array('args'=>$args));
?>Then use the [event_search_form] shortcode.
You could try setting the parameters in the [event_search_form] shortcode instead of in events_search.php
This is, as you already mentioned, definitely not ideal.
Any chance to get this properly fixed in the near future?
I hope so.
Here’s an improved version.
First create the directory wp-content/plugin-templates/events-manager/templates and then create a file in that directory called events-search.php with the following content:
<script>
jQuery(document).ready( function($){
$(window).on('load', function() {
$('button.em-search-submit').click();
});
});
</script>
<?php
/* @var $args array */
$args['search_action'] = 'search_events';
$args['search_url'] = get_option('dbem_events_page') ? get_permalink(get_option('dbem_events_page')):EM_URI;
$args['css_classes'][] = 'em-events-search';
$args['css_classes_advanced'][] = 'em-events-search-advanced';
if (!empty($args['scope']['name'])) $args['scope'] = $args['scope']['name'];
em_locate_template('templates/search.php', true, array('args'=>$args));
?>Then you can use the following shortcode:
[event_search_form full="1" has_search="1" sorting="0" show_advanced="0" search_geo="0" show_search="1" long_events="1"]
Here’s an improved version that handles the javascript in the correct way and will work in the case when the shortcode is instantiated more than once on the same page:
$selector = $args['id'] . ' button.em-search-submit';
wp_enqueue_script( $args['id'] );
wp_add_inline_script( $args['id'],
'
jQuery(document).ready( function($){
$(window).on("load", function() {
$("' . $selector . '").click();
});
});
');
/* @var $args array */
$args['search_action'] = 'search_events';
$args['search_url'] = get_option('dbem_events_page') ? get_permalink(get_option('dbem_events_page')):EM_URI;
$args['css_classes'][] = 'em-events-search';
$args['css_classes_advanced'][] = 'em-events-search-advanced';
if (!empty($args['scope']['name'])) $args['scope'] = $args['scope']['name'];
em_locate_template('templates/search.php', true, array('args'=>$args));
?>If you do instantiate the shortcode more than once it might be a good idea to specify a unique id for each shortcode (but it’s not necessary). For example:
[events_search_form id=1 full="1" has_search="1" sorting="0" show_advanced="0" search_geo="0" show_search="1" long_events="1" category=12]
[events_search_form id=2 full="1" has_search="1" sorting="0" show_advanced="0" search_geo="0" show_search="1" long_events="1" category=13]Here’s a way to register a new shortcode to do this without modifying any template files. Just add the following code snippet:
add_shortcode('events_list_searchform', 'my_events_list_searchform');
function my_events_list_searchform($args = []) {
$selector = 'form#em-search-form-' . $args['id'] . ' button.em-search-submit';
$args = em_get_search_form_defaults($args);
$args['search_action'] = 'search_events';
$args['search_url'] = get_option('dbem_events_page') ? get_permalink(get_option('dbem_events_page')):EM_URI;
$args['css_classes'][] = 'em-events-search';
$args['css_classes_advanced'][] = 'em-events-search-advanced';
if (!empty($args['scope']['name'])) $args['scope'] = $args['scope']['name'];
$script = '<script>
jQuery(document).ready( function($){
$(window).on("load", function() {
$("' . $selector . '").click();
});
})</script>';
ob_start();
em_locate_template('templates/search.php', true, array('args'=>$args));
return ob_get_clean() . $script;
}You can then use the [events_list_searchform] shortcode instead of [events_list] (it takes the same search attributes).
You can use the Code Snippets plugin to add this code snippet.
Thanks for the snippet!
However,
[events_list_searchform full="1" has_search="1" scope="3-months" sorting="0" show_advanced="1" search_geo="0" show_search="1" long_events="1"]
does not work, it throws this console.log messages:externals.js:10 Error: Invalid date provided: a
at Object.parseDate (externals.js:10:8100)
at externals.js:10:34329
at Array.map (<anonymous>)
at pe (externals.js:10:34303)
at w.setDate (externals.js:10:33734)
at HTMLDivElement.<anonymous> (datepicker.js:206:23)
at Function.each (jquery.min.js?ver=3.7.1:2:3129)
at ce.fn.init.each (jquery.min.js?ver=3.7.1:2:1594)
at em_setup_datepicker (datepicker.js:179:18)
at em_setup_ui_elements (index.js:656:3)
externals.js:10 Error: Invalid date provided: l
at Object.parseDate (externals.js:10:8100)
at externals.js:10:34329
at Array.map (<anonymous>)
at pe (externals.js:10:34303)
at w.setDate (externals.js:10:33734)
at HTMLDivElement.<anonymous> (datepicker.js:206:23)
at Function.each (jquery.min.js?ver=3.7.1:2:3129)
at ce.fn.init.each (jquery.min.js?ver=3.7.1:2:1594)
at em_setup_datepicker (datepicker.js:179:18)
at em_setup_ui_elements (index.js:656:3)The list is empty at the beginning, when I click the search button, however, it works and populates the list.
Also, how can I make the advanced search input hidden per default with
show_advanced="1"
?Hi @joneiseman , do you have any idea how to fix the above mentioned issue? The events list using your snippet starts in the past and not on the current date.
My attempt to create a shortcode to work around the problem was not successful. I don’t know how to fix the problem.
A workaround is no longer required. The following shortcode will now work in the latest release:
[events_calendar has_search=1 show_search=1 scope=future view="grid" views=calendar,list,grid,list-grouped]
This will display grid mode and will put the search bar on top which will let you switch between different views. The view=”grid” sets it to be initially the grid format but you can change it to whatever view type you like. The view option was just added in the latest release. Before this it would only show the calendar view when it first loaded.
The following will also work:
[events_list view=grid scope=future has_search=1 pagination=1]
-
This reply was modified 2 weeks, 6 days ago by
joneiseman.
-
This reply was modified 2 weeks, 6 days ago by
- You must be logged in to reply to this topic.