Title: recursive wp_remote_post()
Last modified: May 12, 2020

---

# recursive wp_remote_post()

 *  Resolved [The Three](https://wordpress.org/support/users/3wwwgr/)
 * (@3wwwgr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/recursive-wp_remote_post/)
 * I am trying to create recursive function with `wp_remote_post()` and `wp_ajax_nopriv_`
   action. My code:
 *     ```
       add_action('wp_ajax_recursive_func', 'recursive_func');
       add_action('wp_ajax_nopriv_recursive_func', 'recursive_func');
       function recursive_func(){
          $offset = (!empty($_POST['offset'])) ? $_POST['offset'] : 0;
   
          $posts_args = array(
               'post_type' => 'post',
               'nopaging' => false,
               'numberposts' => 50, 
               'offset' => $offset,
           );
           $posts = get_posts($posts_args);
   
          if ($posts){
             // do something
             wp_remote_post(admin_url('admin-ajax.php?action=recursive_func'), [
               'method' => 'POST',
               'blocking' => false,
               'sslverify' => false,
               'body' => [
                   'offset' => $offset
               ]
           ]);
   
            $offset = $offset + 50;
          } else {
             return false;
          }
       }
       ```
   
 * when i debug i get the following
    1) the function `recursive_func` runs for first
   time 2) the `$offset` is 0 3) the `get_posts()` returns 50 posts 4) the `wp_remote_post()`
   runs 5) the function `recursive_func` runs for second time 6) the `$offset` is
   50 7) the `get_posts()` returns 50 posts 7) the `wp_remote_post()` does not run
 * any idea?
    -  This topic was modified 5 years, 11 months ago by [The Three](https://wordpress.org/support/users/3wwwgr/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [The Three](https://wordpress.org/support/users/3wwwgr/)
 * (@3wwwgr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/recursive-wp_remote_post/#post-12822143)
 * I found the bug, it was at the `// do something` part… the above code is working
   fine 🙂

Viewing 1 replies (of 1 total)

The topic ‘recursive wp_remote_post()’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [The Three](https://wordpress.org/support/users/3wwwgr/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/recursive-wp_remote_post/#post-12822143)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
