lswitzer
Forum Replies Created
-
Forum: Reviews
In reply to: [My Private Site] Nice for most sitesIt doesn’t like the header call after an update to 4.5.1 and the theme combo. Works with other themes. Rating retracted.
Cannot modify header information - headers already sent by
Wow, really? Best Friday present ever!
Here’s what I have running in the theme functions:
function wpaesm_archive_old_data_custom_recurrence( $schedules ) { $schedules['monthly'] = array( 'display' => __( 'Once a day', 'textdomain' ), 'interval' => 86400, ); return $schedules; } add_filter( 'cron_schedules', 'wpaesm_archive_old_data_custom_recurrence' ); /** * Schedule cron job. * * Schedule the archive event to happen daily. * * @since 2.2.0 */ function wpaesm_archive_old_data() { if ( ! wp_next_scheduled( 'wpaesm_export_and_delete' ) ) { wp_schedule_event( current_time( 'timestamp' ), 'daily', 'wpaesm_export_and_delete' ); } } add_action( 'init', 'wpaesm_archive_old_data' ); /** * Find shifts and change. * * Find all shifts on the site that is more than a day old, change to worked status * * @since 2.2.0 * */ add_action( 'wpaesm_export_and_delete', 'wpaesm_do_archiving' ); function wpaesm_do_archiving() { $before = date( 'm/d/Y', strtotime( '-1 day', time() ) ); $csv_list = array(); $changed = array(); $oldshifts = wpaesm_find_old_shifts( $before ); if( false !== $oldshifts ) { $csv_list['shifts'] = wpaesm_export_old_shifts( $oldshifts ); $changed['shifts'] = wpaesm_delete_old_posts( $oldshifts ); } } /** * Find old shifts. * * Find all of the shifts older than the given date. * * @since 2.2.0 * * @param string Date (Y-m-d). * @return WP_Query Object Query of old shifts. */ function wpaesm_find_old_shifts( $before ) { $args = array( 'post_type' => 'shift', 'posts_per_page' => -1, 'meta_key' => '_wpaesm_date', 'meta_value' => $before, 'meta_compare' => '<=', ); $oldshifts = new WP_Query( $args ); if ( $oldshifts->have_posts() ) { return $oldshifts; } else { return false; } } /** * Change old shifts. * * Given a WP_Query object, change all of the posts in the query. * * @since 2.2.0 * @param $oldshifts WP_Query object * * @return int number of changed posts */ function wpaesm_delete_old_posts( $oldshifts ) { $i = 0; while ( $oldshifts->have_posts() ) : $oldshifts->the_post(); $post_id = get_the_id(); $changed = wp_set_object_terms($post_id, 'worked', 'shift_status', false); if( $changed ) { $i++; } endwhile; reset_postdata(); return $i; }
Update: the job registers, I can run it manually but with no changes made to the shifts.
$deleted = array(); should have been $changed = array(); Still nada in the way of auto-working these shifts. If anyone has any suggestions I’d appreciate it. Thanks
It does not seem to be registering the job. I tried running it as is and the shifts remained as is. This should be in the themes functions file, correct?
in functions.php
/** * Schedule cron job. * * Schedule the archive event to happen daily. * * @since 2.2.0 */ function wpaesm_archive_old_data() { if ( ! wp_next_scheduled( 'wpaesm_export_and_delete' ) ) { wp_schedule_event( current_time( 'timestamp' ), 'daily', 'wpaesm_export_and_delete' ); } } add_action( 'init', 'wpaesm_archive_old_data' ); /** * Find shifts and change. * * Find all shifts on the site that is more than a day old, change to worked status * * @since 2.2.0 * */ add_action( 'wpaesm_export_and_delete', 'wpaesm_do_archiving' ); function wpaesm_do_archiving() { $before = date( 'Y-m-d', strtotime( '-1 day', time() ) ); $csv_list = array(); $deleted = array(); $oldshifts = wpaesm_find_old_shifts( $before ); if( false !== $oldshifts ) { $csv_list['shifts'] = wpaesm_export_old_shifts( $oldshifts ); $changed['shifts'] = wpaesm_delete_old_posts( $oldshifts ); } } /** * Find old shifts. * * Find all of the shifts older than the given date. * * @since 2.2.0 * * @param string Date (Y-m-d). * @return WP_Query Object Query of old shifts. */ function wpaesm_find_old_shifts( $before ) { $args = array( 'post_type' => 'shift', 'posts_per_page' => -1, 'meta_key' => '_wpaesm_date', 'meta_value' => $before, 'meta_compare' => '<=', ); $oldshifts = new WP_Query( $args ); if ( $oldshifts->have_posts() ) { return $oldshifts; } else { return false; } } /** * Change old shifts. * * Given a WP_Query object, change all of the posts in the query. * * @since 2.2.0 * @param $oldshifts WP_Query object * * @return int number of changed posts */ function wpaesm_delete_old_posts( $oldposts ) { $i = 0; while ( $oldposts->have_posts() ) : $oldposts->the_post(); $changed = wp_set_object_terms($post->ID, 'worked', 'shift_status', false); if( $changed ) { $i++; } endwhile; return $i; }
Hi Morgan,
I’m totally lost on adding a cron job that actually changes the shifts before the current day to ‘worked’.
The code you supplied was very helpful, however i cant:
`wp_set_object_terms($post->ID, ‘worked’, ‘shift_status’, false);I really really appreciate the help!
I’ll make up a plugin quick. So helpful, thanks so much for sharing- I’m new to php, coming from java and obj-c have been no help! Woohoo
This is perfect! Where would I stick this code, in the theme functions or in the plugin?
I tried to write one but it didn’t do what I wanted. Say I wanted to trash all shifts with an additional status of ‘report-submitted’ appended to ‘worked’. So all shifts with those two categories. Could you help me a little if you have spare time for this? Always appreciated.
To clarify: I just want to change the actual shift title to include the employee name &&/|| the job. The master schedule has all the jobs & employees attached so we’re good there.
Thanks so much for any help- I’m trying things too.
I’m looking to change the WordPress title. I display a list of the shifts and it would be nice to add the connected employee and assigned date to the titles. Thanks so much!
Forum: Plugins
In reply to: [Shiftee Basic - Employee and Staff Scheduling] Can't switch weeksSolved! Thank you again, this is an amazing tool.
Forum: Plugins
In reply to: [Shiftee Basic - Employee and Staff Scheduling] Can't switch weeksSorry! I was going to erase the user right away but thank you- it didn’t feel right.
Forum: Plugins
In reply to: [Shiftee Basic - Employee and Staff Scheduling] Can't switch weekshttps://frontrangenaturals.com/?page_id=635
Just login as:
[removed by moderator – do not post ANY passwords on the forum]