Forums Forums Search & Filter Pro Display results greater than date

Tagged: 

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #204619

    Hello,

    We’re trying to display search results that are greater than a date.

    This date will be selected by the user, and pulled from a custom Meta Key that we’ve set up.

    We’ve got this working as a date range currently, but that relies on a user selecting two dates – and doesn’t allow for indefinite dates.

    Is it possible to display results greater than a single selected date?

    Thanks

    Trevor
    #204624

    By way of a ‘trick’ yes. Make it a range as you did, but use CSS to hide the TO date field, and use javascript to fill this field on document ready, with a date far into the future. The user sees only the from field.

    Anonymous
    #204648

    Just having a look into this, and wondered how I go about targeting the TO date field.
    It appears that the ID for this field is randomised on each load:

    <input class=”sf-datepicker sf-input-date sf-input-text hasDatepicker” name=”_sfm_startdate[]” type=”text” value=”” title=”” id=”dp1552313064514″>

    Trevor
    #204660

    It will be the last-child of the containing field. Here is one I made a while ago:

    .sf-field-post-meta-transportation_dummy_start_date > ul > li:last-child {
      display: none;
    }

    And the javascript I used (your need may vary, for example the date format):

    <script type="text/javascript">
    jQuery( document ).ready(function($){
      jQuery('li:last-child input[name="_sfm_transportation_dummy_start_date[]"]').val('31/12/2050');
    });
    </script>
    Anonymous
    #205587

    Hi Trevor,

    Many thanks for the above.

    We’ve got an odd issue whereby the “To” date being set is causing differences in the results to what we previously had.

    For example, if we leave both the “From” and “To” date empty prior to the code you provided we’re seeing a set of resutlts.

    However, if we populate the “To” date with 31/12/2050 and leave the “From” field blank we don’t retrieve any results.

    I can confirm that we don’t have any resutls that exceed the 31/12/2050 date.

    Let me know if you need any further information.

    Thanks.

    Trevor
    #205625

    In order for a date range to work, BOTH fields must be completed. What I have done in the past is to set a default in the other field of today (again using Javascript).

    Anonymous
    #205632

    In the above case, would it best to check for a value in the FROM field – instead of populating the TO field on page load?
    If a value exists, when submitting, the TO field is populated with the 31/12/2050 date?

    Trevor
    #205640

    Yes, maybe so. You mean check if any value has been inserted, and only if it hasn’t, then add a date? The question is how you would you do this?

Viewing 8 posts - 1 through 8 (of 8 total)