Tell us what you are trying to do?
I need to filter a view based on a custom Date/Time field by passing the Date/Time argument as Shortcode attribute. What format do I use to pass the timestamp to the view? I have tried several variations such as: start="2020-03-21 14:10:00", etc. None of them return any results.
I am able to pass numeric or text arguments to the view, but have been unable to pass a DATE/TIME argument.
Hello. Thank you for contacting the Toolset support.
The thing is that Types stores custom date field value as a UNIX timestamp to the database.
To filter the view using your custom date field, you need to pass either UNIX timestamp value that is the equivalent value of Unix timestamp to your date field.
OR
You can pass the readable date as you are passing currently: start="2020-03-21 14:10:00"
And use the view's filter query hook: wpv_filter_query hook where you should catch the passed start shortcode attribute value and convert it to UNIX timestamp and pass the related custom field filter.
As I understand, you wnat to display posts that is less than or equal to the start date value -that is passed using the view's shortcode attribute correct?
Please let me know with what option you would like to go with and I will guide you accordingly.
add_filter( 'wpv_filter_query', 'func_custom_attribute_to_views', 99, 3 );
function func_custom_attribute_to_views( $query_args, $view_settings, $views_id ) {
if ( $views_id == 9999 ) {
global $WP_Views;
$attributes = $WP_Views->view_shortcode_attributes;
}
return $query_args;
}
Where:
- Change the 9999 with your original view ID
- You can find the passed shortcode attribute start with the $attributes variable as shown above.
- You can get the passed attribute and convert it to Unix timestamp and you need to adjust the query argument
Please let me know if you require further assistance.