Forums › Forums › Search & Filter Pro › Datefilter
Tagged: current date, custom date, events, V3
- This topic has 31 replies, 2 voices, and was last updated 4 years, 7 months ago by Trevor.
-
Trevor(Private) April 3, 2020 at 10:34 am #238869
So, in the child theme functions.php I have added this code at the end:
function event_date_year_on_save( $post_id ) { $post_type = 'dig_veranstaltungen'; //custom post type for events //Check if we are saving correct post type if( get_post_type( $post_id ) != $post_type) return; //Check it's not an auto save routine if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return; // get the event date of the post. Note this is in YYYYMMDD format $event_date = get_post_field ('veranstaltungs_datum_beginn', $post_id); // update the event year value update_field( 'jahr', substr( $event_date , 0, 4 ), $post_id ); } add_action('save_post', 'event_date_year_on_save');
It is really easy to get the year because it is the first four characters of the event date!
Try it for yourself. Edit and event and change the event date (to a different year). No need to change the Year (jahr) you will see it changes automatically.
I also added a little bit of CSS (in the theme customizer) to make the form nicer, and the year field also, plus German labels.
Once you are happy that works, make these changes:
https://www.screencast.com/t/yYKJTzoMp3
Now the user will not see this field in the admin editor.
All you have to do is edit the events and save. You do not actually need to make any changes, the save is to trigger the code to add the year.
Trevor(Private) April 3, 2020 at 11:26 am #238898Current year is harder, as it cannot be predefined. Is this on the same page of a different page, and by ‘current year’, do you mean only future events in the current year, OR past and future events?
It would have a really odd effect as you approach the ‘next year’.
Or, do you want the choices shown in the dropdown box to be:
Current Year
Next Year -
AuthorPosts