Use single date input as lower bound for date meta

Forums › Forums › Search & Filter Pro › Use single date input as lower bound for date meta

Viewing 6 posts – 1 through 6 (of 6 total)
  • Anonymous
    #238762

    I’m trying to figure out whether it’s possible to use a single date input as a lower bound for posts containing a ‘start date’ meta, so that if I input for example 2020-04-15 it will return me all posts having a start date of that AND later in the future. Right now it only returns posts having exactly that start date.

    If I add a filter to sf_edit_query_args, I can’t see the date or any meta query arguments entered in the search form, same goes for the sf_main_query_pre_get_posts filter. Is it possible to hook in anywhere to change the meta_compare type of the query for the start date meta key?

    Trevor
    #238785

    It is, by a small hack. Set the field up as a date range and then, in the form in the front end, use custom CSS to hide the display of the To field.

    You will also need some PHP to add a distant date into the To field in the query arguments, using this filter (which I think you know already):

    https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments

    Anonymous
    #239148

    How would I go about adding the To-date into the query? This is the query args that I get when I add the sf_edit_query_args filter (even with dates put in):

    Array
    (
        [paged] => 1
        [search_filter_id] => 144
        [search_filter_override] => 
        [posts_per_page] => 10
        [post_status] => Array
            (
                [0] => publish
            )
        [meta_query] => Array
            (
            )
        [post_type] => cursus
        [post__in] => Array
            (
                [0] => 0
            )
    )

    I can’t see any of the form inputs here, the only thing that seems to change is when I put in a search word, the [s]-arg is added.

    Trevor
    #239152

    mmm. Maybe you need to use jQuery to add the To date then actually in the form, on document ready?

    Anonymous
    #239347

    Thank you, that worked!

    (still, it would be a nice feature to be able to set the compare type on a date filter input ;))

    Trevor
    #239353

    I think this will change in V3 (due soon). I will close this thread for now.

Viewing 6 posts – 1 through 6 (of 6 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.