[wp-hackers] Stopping recursion with save_post/wp_insert_post action

Azizur Rahman prodevstudio+wordpress at gmail.com
Sat Aug 21 03:27:04 UTC 2010


Hi All,

I am writing a plugin that hooks into wp_insert_post action.

The problem is that I am going into recursion at the moment and not sure how
to stop it.

Here is the pseudo code logic
*********************************************************************
on wp_insert_post or save_post

check the $post->content for x.
return if  x is NOT found

if x is found do
   if x does NOT have meta key/value _x_details_ set
       $x_details_id = wp_insert_post( $x_details);
       add_post_meta($post_ID, '_x_details_', $x_details_id, true);
end
*********************************************************************
I am sure you can see the recursion I am getting myself into when calling
wp_insert_post( $x_details);

what is the best way to stop this recursion?

Is there a better way of doing this?


Thanks in advanced!

Kind Regards,

Azizur Rahman


More information about the wp-hackers mailing list