Hi,
Thanks for writing back.
Here are the details of the setup that I used on my test website:
1. I added a single line custom field 'book-day', to my 'books' post type, and stored the weekdays in the different book posts, based on the days, I'd like to show them.
( e.g. Sunday, Monday, Tuesday, Wednesday, Thursday, etc )
2. Next, I used the following code snippet, to make the view only show the book posts, where the 'book-day', custom field value is the same as today's weekday:
add_filter( 'wpv_filter_query', 'filter_date_custom_fn', 1000 , 3 );
function filter_date_custom_fn( $query_args, $view_settings ) {
if ( (!is_admin() && isset($view_settings['view_id'])) && ($view_settings['view_id'] == 12345) ) {
$query_args['meta_query'] = array(
'relation' => 'AND',
array(
'key' => 'wpcf-book-day',
'value' => date("l"),
'type' => 'CHAR',
'compare' => '=',
)
);
}
return $query_args;
}
Note: You'll replace '12345' with the ID of the view where you'd like to apply this filtering.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
I hope this helps and here are some useful guides on the topic:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/
For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar