Tell us what you are trying to do?
Hi, toolset
I have this code for one of my tables that shows the past bid date for all my posts. The Bid date is a custom date field. Upon load and when searching it will show me all past dated posts.
Here is the 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.
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($_GET['wpv-wpcf-bid_date'])) && (!empty($_GET['wpv-wpcf-bid_date'])) ) {
$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;
}
The error I receive is:
PHP Warning: Illegal string offset 'key' in /home/w2nnms2ait2i/public_html/wp-content/toolset-customizations/past-bid-table.php on line 16
Line 16 is: if ($value['key'] == $target_field){
Would you help me in figuring out why this might be happening?
- Andrew