[wp-hackers] Stopping recursion with save_post/wp_insert_post action
Nathaniel Taintor
goldenapplesdesign at gmail.com
Sat Aug 21 04:14:13 UTC 2010
Or, check for the post type at the beginning of your function.
Presumably you wouldn't need to run this function on a media
attachment, so if $post->post_type == 'attachment' then return.
Than
On Aug 21, 2010, at 12:01 AM, ProDevStudio <prodevstudio at gmail.com>
wrote:
> I am calling wp_insert_post again to place a media attachment.
>
> I think I found a way... which is to remove the action before calling
> wp_insert_post again.
>
>
> Kind Regards,
> Azizur Rahman
>
>
> On Sat, Aug 21, 2010 at 4:51 AM, Otto <otto at ottodestruct.com> wrote:
>
>> Why are you calling wp_insert_post again?
>>
>> -Otto
>>
>>
>>
>> On Fri, Aug 20, 2010 at 10:27 PM, Azizur Rahman
>> <prodevstudio+wordpress at gmail.com <prodevstudio
>> %2Bwordpress at gmail.com>>
>> wrote:
>>> 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