Skip Navigation

[Resolved] date format of wpv-control-postmeta url_param

This thread is resolved. Here is a description of the problem and solution.

Problem:
Customize the date format in URL param of views filter.

Solution:
You need to add custom JS to your view's "Search and Pagination" section's JS box.

You can find the proposed solution, in this case with the following reply:
https://toolset.com/forums/topic/date-format-of-wpv-control-postmeta-url_param/#post-1216765

Relevant Documentation:

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by bryan 5 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#1215190
custom date.png
views-select.png
toolset-result.png
gravity-date.png

Good Morning,

Tell us what you are trying to do?

Select date on one page and pass as a url_param to another;

simply explained

[wpv-filter-controls]
....

	[wpv-control-postmeta field="wpcf-date-available" url_param="tbk_date"]

the url generated is almost OK !

.../?wpv-relationship-filter=822&tbk_date=1553990400&tbk_date-format=Y-m-d&wpv_filter_submit=Submit

but the desired result is for example

.../?wpv-relationship-filter=822&tbk_date=20190331

...so a human readable rather than unix timestamp and it would be nice to lose the -format=Y-m-d which I cannot figure out where it is coming from !

wpcf-date-available is just a simple toolset custom date field

Is there any documentation that you are following?

no - I am not sure where to start - for example can this be solved by an parameter in views, or do I need to somehow render the custom date field.

Is there a similar example that we can see?
I can get something similar to work with gravity forms
hidden link

What is the link to your site?
hidden link
this link
hidden link

thanks !

#1215278

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - the thing is that Toolset date custom field stores the date value as Unix timestamp. That is why the selected date field value in URL param shown as the UNIX timestamp but not as your desired date format.

What I suggest is you should try to catch the URL param value that is available as UNIX timestamp and convert it to your date format using the custom shortcode wherever you want to display its value.

#1215324

Thanks Minesh,

Ideally the other plugin would be able to convert a unix time stamp to YYMMDD but it doesn't, although it accepts almost any date format !

The reason I am asking toolset is that this is easily achieved in a few minutes in a gravity form -- but but - but more than that either Views or the types custom field is generating this confusing parameter.

&tbk_date-format=Y-m-d

 &tbk_date=1552089600&tbk_date-format=Y-m-d 

is being generated by:

 [wpv-control-postmeta field="wpcf-date-available" url_param="tbk_date"] 

any idea this coming from ? it just looks like something in views is passing on a date format parameter which is just wrong - or as I thought i am missing an essential parm in the views filter.

thanks

#1215457

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - what if you try to add the following code to your view's "Search and pagination" section's JS box:

jQuery(document).ready(function ($) {
        jQuery(".wpv-submit-trigger").on("click",function(){
             $("input[name='tbk_date']").val($(".hasDatepicker").val());
            });
  
 });
#1216711

Minesh

thank you very much that's very helpful, unfortunately the &tbk_date=ddmmyyyy format I see now is problematic as its sometimes impossible to know what is a month and what is a day !

I thought this might be coming from the wordpress settings - but changing the Date Format under

Settings >> General

had no effect other than to change the output of the query parameter to make it confusing e.g.

 &tbk_date=21032019&tbk_date-format=Y-m-d

I spent some time trying to understand hasDatepicker but was unable to find a way to change the date output format... and datepicker.

so I have two final questions / requests.

1. Do you think we can change the tbk_date=ddmmyyy param to tbk_date=yyyyyddmm using jQuery or should the wordpress date format setting be determining hasDatepicker format ?

2. Is it expected behavior for

 &tbk_date-format=Y-m-d 

to be sent as a url parameter - I ask as it serves no purpose other than add confusion.

thanks again - these are my only remaining questions in the area you have been so helpful assisting me in.
cheers

#1216765

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - what if you try to use the following code - just add it to your view's "search and pagination" sections JS box:

jQuery(document).ready(function ($) {
  
  
           jQuery(".wpv-submit-trigger").on("click",function(){
             datestr = $(".hasDatepicker").val();
             var day = datestr.substring(0, 2);
             var month = datestr.substring(2, 4);
             var year = datestr.substring(4,8);
             $("input[name='wpv-wpcf-birth-date']").val(year+day+month);
           
             
           });
  
        });
#1216809

Minesh,

Nice thinking outside the box - thank you !

I guess there is no getting rid of the

&tbk_date-format=Y-m-d

? ...never mind I i can live with that.

I made some minor modification and for the record the code which worked is:

jQuery(document).ready(function ($) {
   
           jQuery(".wpv-submit-trigger").on("click",function(){
             datestr = $(".hasDatepicker").val();
             var day = datestr.substring(0, 2);
             var month = datestr.substring(2, 4);
             var year = datestr.substring(4,8);
             $("input[name='tbk_date']").val(year+month+day);
            
           });
   
        });

I only leave this open in case you have some comment on the extraneous &tbk_date-format=Y-m-d..

thanks again

#1216924

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

No - there is no other solution I can think of. I tried to share the solution as you know that help you the best and help you to resolve your issue.

Please feel free to resolve this ticket 🙂

#1217310

Nicely resolved by Minesh with some out of the box thinking to overcome some functional limitations in the way dates are handled by views.

For the record this is an example based on some simple extension to the discover-wp travel destinations site using teambooking as the booking engine which accepts a query parameter to select a single date - and the code which worked is as follows:

/**
* Hide Submit Button - until Country and Date are selected
* get the date selected and convert to teambooking readable date
* name="tbk_date" is defined in the views filter as the url_param - and not the field name !
*  [wpv-control-postmeta field="wpcf-tour-date" url_param="tbk_date"]
*/

jQuery(document).ready(function($){
    $('input[name="wpv_filter_submit"]').hide();

   jQuery(".wpv-submit-trigger").on("click",function(){
             datestr = $(".hasDatepicker").val();
             var day = datestr.substring(0, 2);
             var month = datestr.substring(2, 4);
             var year = datestr.substring(4,8);
             $("input[name='tbk_date']").val(year+month+day);

           });
});

jQuery("input[name='tbk_date']").on('change keyup paste', function () {

   var value = jQuery('input[name="tbk_date"]').val();
   if(value == '' || $('select[name="wpv-relationship-filter"]').val() == 0){
      $('input[name="wpv_filter_submit"]').hide();
    }else{
      $('input[name="wpv_filter_submit"]').show();
    }
});

  jQuery("select[name='wpv-relationship-filter']").on('change', function () {

   if($('select[name="wpv-relationship-filter"]').val() == 0 || jQuery('input[name="tbk_date"]').val()==''){
      $('input[name="wpv_filter_submit"]').hide();

   	 }else{
      $('input[name="wpv_filter_submit"]').show();
    }

});

jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function( event, data ) {


   if($('select[name="wpv-relationship-filter"]').val() == 0 || jQuery('input[name="tbk_date"]').val()==''){
      $('input[name="wpv_filter_submit"]').hide();

   	 }else{
      $('input[name="wpv_filter_submit"]').show();
    }

});