Skip Navigation

[Resolved] Split: Between Dates – past dates one day

This support ticket is created 4 years, 1 month 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 7 replies, has 2 voices.

Last updated by andrewD-10 4 years ago.

Assisted by: Minesh.

Author
Posts
#1561061

Hi Minesh,
Sorry for late response. Thank you very much for your help in accomplishing this.

As far as the other issue.

The Past Bid Table should only show bid dates that are yesterday and past. Similar to this filter we did it will show the past date and everything before that date. Here is the code to make this happen.

/**
* New custom code snippet (replace this with snippet description).
*/

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.
function filter_bid_date_default_pasttable($view_args, $view_settings, $view_id) {
$timestamp = current_time('timestamp');
$yesterday = strtotime('-12 hours', $timestamp);
if (in_array($view_id, array(41104))) {
// slug of the bid date field
$bid_field_slug = "wpcf-bid_date";

// check for the existing meta query filters
if(!empty($view_args['meta_query'])) {
foreach ($view_args['meta_query'] as $meta_query_arr ) {
if( (!empty($meta_query_arr['key'])) && (isset($meta_query_arr['key'])) ) {
$available_keys[] = $meta_query_arr['key'];
}
}
}
else {
$available_keys[] = '';
}

// if no user filter for the bid date exists add a fixed one
if (!in_array($bid_field_slug, $available_keys)) {
$view_args['meta_query'][] = array(
'key' => $bid_field_slug,
'value' => $yesterday,
'type' => 'CHAR',
'compare' => '<='
);
}
}

return $view_args;
}
//add_filter('wpv_filter_query', 'filter_bid_date_default_pasttable', 99, 3);

This code is no longer working as we have made changes to that table by adding more code above for the filter you just fixed.

#1561065

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I do not think the above code you shared is shared by me that should help you to resolve your issue.

Can you please share the problem URL and what is your expected results you want to output.

#1561729
Screen Shot 2020-03-24 at 9.46.02 AM.png
Screen Shot 2020-03-24 at 9.45.41 AM.png

Hi Minesh,
Thank you for creating a new ticket for me.

Yes, no problem. I will share with you the link and screenshots on what it does currently and what it should do.

Link: hidden link

This link is supposed to show all the posts that have a bid date that is less than < "today's date". However, with the new code we put in, it is now showing posts that are equal to and less than <= "today's date". This is with no filter added, only how the page will load the first time we go to it.

In the screenshot below you will see that today's date is 03-24. The link should only be showing bid dates 03-23, but it is now showing 03-24. The desired results are for the table to show 1 day less than today's date ie: x<today's date (not <=)

#1562557

Minesh
Supporter

Languages: English (English )

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

Ok - as I understand, when the page is loaded, by default, it should display all the posts whose date is 1 day less. So, this is about when page loaded and view loaded.

When the user selects the filter - the code I shared in previous ticket, that is OK - no need to change that, correct?

#1565869

Hi Minesh,
Sorry for the late response

Yes exactly, when first loads it should only show yesterday's date = 1 day less.

The code you provided works perfectly and no need to change, Thank you!

#1568017

Minesh
Supporter

Languages: English (English )

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

I tried to use the access details you shared in the previous ticket but using that access details I could not able to access the admin section.

Can you please send me admin access details so I can check the issue further.

I have set the next reply to private which means only you and I have access to it.

#1570803

Minesh
Supporter

Languages: English (English )

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

Can you please check now. I've disable the filter code which you added with the custom code snippet "pasttable-prefilter" as that code was not required anymore.

I've adjusted the filter I've added with the custom code snippet "toolset-custom-code" as given under:

add_filter( 'wpv_filter_query', 'func_filter_custom_date_with_fulldaytime1', 99, 3 );
function func_filter_custom_date_with_fulldaytime1( $query_args, $settings, $view_id ) {
   
    if ( $view_id == 41104) {
         
          if ( (isset($query_args['meta_query'])) && (!empty($query_args['meta_query'])) ) {
  
             $target_field = "wpcf-bid_date"; // change this field slug to your field slug
  
             
            
            foreach ($query_args['meta_query'] as $key => $value):
                                       if ($value['key'] == $target_field){
                                         
                                         
                                              $day_start_time =   $value['value'];
                                              $day_end_time = strtotime('+1 day', $day_start_time) - 1;
                                                              $filer_index = $key;
                                         
                 }
            endforeach;
             
  
            if ( isset($filer_index) ) {
                  
                $query_args['meta_query'][$filer_index] = array('key' => $target_field, 
                                                                  'value' => $day_end_time, 
                                                                  'type' => 'NUMERIC', 
                                                                  'compare' => '<=' );
                                                                  }     
            
         
        } else {
          
            $bid_field_slug = "wpcf-bid_date";
            $timestamp = current_time('timestamp');
            $yesterday = strtotime('-12 hours', $timestamp);
   
             
            $query_args['meta_query'][] = array(
                'key' => $bid_field_slug,
                'value' => $yesterday,
                'type' => 'NUMERIC',
                'compare' => '<='
            );
        
       }  
      
     }
    return $query_args;
}

Can you please confirm it works as exptected: hidden link

#1573505

Hi Minesh,

Thank you for helping get this problem fixed! You are awesome 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.