I'm trying to run a WP cron job which, every hour, checks for recently created/updated posts and runs a filter on them.
if ( $post->post_type == "species" ) {
$meta = get_post_custom( $post_id );
/* --- */
update_option( 'error_check', $meta );
/* --- */
$values_to_filter = array( "distribution", "habitat", "max_size", "aquarium_size", "maintenance", "water_chemistry", "diet", "behaviour", "dimorphism", "reproduction", "misc_notes" );
//$values_to_filter = array( "distribution", "habitat" );
foreach ( $meta as $key => $val ) {
if ( isset( $val ) && isset( $val[0] ) && !empty( $val[0] ) ) {
if ( in_array( $key, $values_to_filter ) ) {
$updated_meta = filter( $val[0], $species_terms, "species" );
$updated_meta = filter( $updated_meta, $glossary_terms, "glossary" );
update_post_meta( $post_id, $key, $updated_meta );
}
}
}
/* --- */
update_option( 'error_check', "should've worked!!" );
/* --- */
}
At :50 of every hour, the function runs, and my error_check option is updated to the value of $meta - the code never reaches the second option update, nor does the filter itself actually work.
The thing I can't understand is that if I change $values_to_filter to only distribution and habitat, as per the commented line, the filter runs successfully.
However, when I use all of the values, something goes wrong.
The problem I'm having is that I can't debug what's going wrong! I presume that the script is timing out or something, but I have no way of telling.
What's the best way to go about debugging this problem? Is there a way I can get the PHP error messages into update_option? Understanding PHP as I do, which is a reasonable amount but no expert, I doubt it.
I can't run this function on save_post - it's a time-consuming function, hence running it as a cron. I simply get a server error when I try to do this (possibly the way my server is set up).
Any suggestions appreciated.
Thanks in advance,
save_postRarst - it times out. Is there another way I can "just run it"? – dunc Mar 28 '12 at 17:47