Hi
I’m currently using the plugin CalendarizeIT with Toolset. I’d like to display the post entries as future events and hide the old entries (older than today – hidden link). The custom field used to generate the date is “fc_start” which comes from CalendarizeIT ( hidden link ).
I did use this filter hidden link but it doesn’t work. I assume then that “fc_start” doesn’t store timestamp value.
Since I understood there’s no way to make “fc_start” act like Toolset’s default time field ( hidden link ) is there a way to automatically fill Toolset’s default time field with the contents of “fc_start” so that I can then prevent the older posts entries from appearing?
I also understood that one could build a custom function following this tutorial https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/. That function will get the assigned value from the field “fc_start”, convert it into UNIX timestamp format and then add it to Toolset new date type custom field.
I tried to use this function but it doesn't work
function udpate_event_datefield( $post_id, $post ){
if ( 'event-date-field' == $post->post_type ) {
$deadline = get_post_meta( $post_id, 'wpcf-deadline', true );
$now = time();
if ( !empty($deadline) && $now > $deadline ) {
update_post_meta( $post_id, 'fc_start', 1 );
}
}
}
add_action( 'save_post', 'udpate_event_datefield', 30, 2 );
Thank You
Hi Marian,
Thanks for asking! I'd be happy to help.
Can you please share temporary admin user's login details, so that I can see how these fields are set up?
Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.
regards,
Waqar
Hi Marian,
Thank you for sharing the access details.
I'll recommend the following steps:
1. I've noticed that you've added the Toolset's date type custom field with the slug "date-start".
To automatically populate its value, based on the value selected in the "fc_start" field, please update your custom function to:
function auto_update_date_field( $post_id ) {
if ( get_post_type( $post_id ) == 'events' ) {
$fc_start = get_post_meta( $post_id, 'fc_start', true );
if(!empty($fc_start)) {
$date_obj=date_create($fc_start);
update_post_meta( $post_id, 'wpcf-date-start', date_format($date_obj,"U") );
}
}
}
add_action( 'save_post', 'auto_update_date_field', 99 );
As a result, when a new or existing event will be updated from the admin area, this new date field's value will be automatically updated too.
2. In your view's "Query Filter" section, add a filter for this new date type custom field as shown in this example screenshot:
hidden link
I hope this helps and let me know how it goes.
Note: 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
Awesome Help. My issue is resolved now. Thank you!