wp_insert_posts Fatal error: Maximum function nesting level of ‘100’ reached, aborting!

Fixed the problem I’ve added this line before the insertion of the posts.

remove_action('save_post', __FUNCTION__);

final code:

add_action('save_post', 'save_post_func');

function save_post_func(){
    remove_action('save_post', __FUNCTION__);

    include_once(ABSPATH . WPINC . '/feed.php');

    $rss = fetch_feed($url);

    if (!is_wp_error($rss)) {

        $maxitems = $rss->get_item_quantity(5);

        $rss_items = $rss->get_items(0, $maxitems);

        foreach ($rss_items as $item) { 
            wp_insert_post(array('post_title' => 'a')); 
        }

    }

}

Leave a Comment