recursive wp_remote_post()
-
I am trying to create recursive function with
wp_remote_post()
andwp_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 functionrecursive_func
runs for first time
2) the$offset
is 0
3) theget_posts()
returns 50 posts
4) thewp_remote_post()
runs
5) the functionrecursive_func
runs for second time
6) the$offset
is 50
7) theget_posts()
returns 50 posts
7) thewp_remote_post()
does not runany idea?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘recursive wp_remote_post()’ is closed to new replies.