Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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,

share|improve this question
Does it work if you just run it, without cron involved? – Rarst Mar 28 '12 at 15:20
That's what I mean by running the function on save_post Rarst - it times out. Is there another way I can "just run it"? – dunc Mar 28 '12 at 17:47
Basically create a tiny plugin (or whatever you find convenient), call your function from it and explicitly run in some form so you see front-end output. – Rarst Mar 28 '12 at 18:21
Hmm, I'm not sure I follow. How would I be able to run this function from a plugin? – dunc Mar 28 '12 at 19:02
How do you run any function from a plugin? Or just drop it in your theme. Or whatever. The point is - figure out first if function work in principle before moving on to cron. – Rarst Mar 28 '12 at 19:03

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.