1 Answer
1

This is because the first time you go round the loop $post is the current post. But the second time you go around the loop, $post has not changed. The same thing happens the 3rd, 4th, 5th, etc

Because the $post variable is the current post of that page, not the post you've just saved/inserted, the loops if statement will always be true, and an infinite loop entails. Instead of checking the $post variable, you should check the ID of the post that is being saved. If we look at the call that executes the action savE_post:

do_action('save_post', $post_ID, $post);

We now see that save_post has parameters!! So if we indicate when adding that the function accepts 1 parameters: