Video: hidden link
Hi Toolset,
Below is custom code I got a while back. What it does is filter a table to only show the current bidding projects. This means that the table will only show posts that have a date field that has a date and time (right now) and into the future. This table will not show any posts that have a past date or time.
This is an issue as I want this table to show any and all posts that have a date of today and into the future (disregard time).
For example, the current time is 11:30 am. The current set up will show a post with a date and time of 05-27-2020 12 pm but it won't show a post with a date and time of 05-27-2020 10 am. What I would like is for the table to show any post with a date of 05-27-2020 and forget about the time. Essentially the custom code should not count for the time and only go from 12 am of today and into the future.
Not good: Today and Current Time -> Future
Good: Today 12 am -> Future
Custom Code:
<?php
/**
* 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_current_bids($view_args, $view_settings, $view_id) {
if (in_array($view_id, array(40875))) {
// 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' => current_time('timestamp'),
'type' => 'CHAR',
'compare' => '>='
);
}
}
return $view_args;
}
add_filter('wpv_filter_query', 'filter_bid_date_default_current_bids', 99, 3);