Event Search Bar date function

Home Forums Calendar Products Filter Bar Event Search Bar date function

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1180608
    Derek
    Participant

    Hi,

    When using the classic search bar to search by date it appears to be searching for any date after the date I search. Where/how can I customize it so it only searches for the date entered?

    Thanks for your help,
    Derek

    #1182102
    Nico
    Member

    Hi there Derek,

    Thanks for reaching out to us! I can help you here šŸ™‚

    The date range that will be shown after searching for a specific date will depend in the view you are currently in. For example, if you are in day view (only shows events of the day) then this will work as you describe, but if you are in month view, all the month will be shown.

    Are you trying to change this for list view? If that’s the case maybe I can craft a snippet to adjust the time period to just one day.

    Please let me know about it,
    Best,
    Nico

    #1182225
    Derek
    Participant

    Hi Nico,

    I am in photo view.

    Thank you for your help!
    Derek

    #1182234
    Derek
    Participant

    More details to make sure I’m clear, I am hosting an event that takes place April 1st-8th. I’d like when a person searches the calendar for a single day they only see events from that date.

    I am using community events and the filter bar as well.

    Thank you again!
    Derek

    #1182914
    Nico
    Member

    Thanks for clarifying Derek!

    One more thing before I give this snippet a try: if no date is selected do you still want to limit the events shown to the current day? Or do you want this limit to take effect when a date is selected in the picker?

    Please let me know about it,
    Best,
    Nico

    #1182980
    Derek
    Participant

    Thanks Nico!

    I only want to filter the calendar to a specific date if the user selects a date to search by. The calendar would show all events by default and a user could filter it to a single day using the date picker.

    Thanks for your help!

    #1184418
    Nico
    Member

    Thanks for the patience while I worked on this Derek!

    Please try pasting the following code in your theme’s (or child theme’s) functions.php file:


    /* Tribe, limit tribe bar date search to one day */
    add_action( 'tribe_events_pre_get_posts', function( $query ) {
    $ajax_or_main = ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || $query->is_main_query();

    if ( ! $ajax_or_main || empty( $_REQUEST['tribe-bar-date'] ) ) {
    return;
    }

    if ( ! preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $_REQUEST['tribe-bar-date'], $matches ) ) {
    return;
    }

    $end_date = date('Y-m-d', strtotime( $matches[0] . ' +1 day') );

    $query->set( 'end_date', $end_date);
    } );

    Please let me know if it works for you,
    Best,
    Nico

    #1184430
    Derek
    Participant

    Nico,

    It looks like that worked!

    Thank you so much for your help on this.

    Would you be able to help on another issue?

    I’d like to change the bootstrap-datepicker.js to only show the month of April as well as change startDate and endDate to April 1st-8th. So they user only sees April and only has the option to select April 1st-8th when searching/creating an event.

    Thank you again,
    Derek

    #1185600
    Nico
    Member

    Thanks for following up Derek!

    Iā€™d like to change the bootstrap-datepicker.js to only show the month of April as well as change startDate and endDate to April 1st-8th. So they user only sees April and only has the option to select April 1st-8th when searching/creating an event.

    Well, I’m not sure how to do this I’d say you’ll need to take a look at the Bootstrap Datepicker documentation to see if that can be set and how. Once you got that you can ‘remove’ the date picker from the field, change the options and re-add it to the field. This reply shows how to do so ā†’
    https://theeventscalendar.com/support/forums/topic/some-problems-with-events-calendar-pro-new-user/#dl_post-1127004

    Please let me know if that helps,
    Best,
    Nico

    #1195915
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Event Search Bar date function’ is closed to new replies.