php - Wordpress action starting before it's done -
i'm trying create new bbpress forum when new post saved...i made out code thing it's infinite loop. strange loop starts not when save post, first, when go in "all posts" or in "new posts". what's problem please?
this code
<?php add_action('save_post', 'register_forumcustom'); function register_forumcustom($post_id){ $post = get_post($post_id); // create post object $my_new_post = array( 'post_title' => 'forum di'.$post->post_title, 'post_content' => '', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'forum' ); // insert post database $new_forum_id = wp_insert_post( $my_new_post ); //ok, maybe here loop starts, know problem because there "save_post". can solve this, don't understand other problem! update_post_meta($post_id, "forum_id", $new_forum_id); } ?>
you created infinite loop action.
you have unhook action , re-hook when done:
// unhook remove_action('save_post', 'register_forumcustom'); // updates/inserts // re-hook add_action('save_post', 'register_forumcustom');
see: http://codex.wordpress.org/plugin_api/action_reference/save_post#avoiding_infinite_loops
Comments
Post a Comment