Hi @da2handz,
I have just released the new version. You can update and test it.
Only to recall your needs:
– you have some posts, already published, that talk about upcoming events;
– these posts have a custom field named date
where the date of the event is stored;
– the date of the event is in the future;
– you want to display only the events that have the date – stored in the custom field – in the future compared to now.
For this specific reason I added the possibility to use now
in the field “Getting posts” > “Custom fields query” > “Custom field value”. The word now
is a special text that is automatically converted (if used) into a formatted date and time.
Take note that the word now
will be converted into current date and time, using the format you have defined in your dashboard (see Settings > General > Date format and also Time format).
This means that, if your stored custom field is in the same format as in WordPress Settings, the widget will display the posts as intended. For example, if you have
WordPress Settings: 2019-11-10 10:56:18 (year-month-day hours:minutes:seconds)
Stored value in custom field: same as above
you will get posts correctly.
But, if you have instead:
WordPress Settings: November 10, 2019 10:56:18 (month in letter + day, year hour:minute:second)
Stored value in custom field: 2019-11-10 10:56:18
you will not get posts.
In this second case, you won’t have to change WordPress setting for date and time. You can use a function to change how the plugin must handle date and time.
For example:
function change_posts_in_sidebar_now( $formatted_date, $widget_id ) {
if ( empty( $widget_id ) ) {
return;
}
if ( 'pis_posts_in_sidebar-2' === $widget_id ) {
$date_format = 'Y-m-d H:i:s';
$local_timezone = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
$now_timestamp = time() + $local_timezone;
$formatted_date = date( $date_format, $now_timestamp );
}
return $formatted_date;
}
add_filter( 'cf_value_a1', 'change_posts_in_sidebar_now', 10, 2 );
Only change the ID of the widget pis_posts_in_sidebar-2
, if needed. You can get the ID of the widget looking in the Debugging panel of the widget admin.
Let me know, please.