Last active
December 7, 2021 22:33
-
-
Save stokesman/0de15c080b2390e9a802e9e7955f9f39 to your computer and use it in GitHub Desktop.
WP insert new posts from remote WP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
['body' => $payload] = wp_remote_get( '/wp-json/wp/v2/posts/?categories=10&per_page=20' ); | |
$post_list = json_decode( $payload ); | |
foreach ( $post_list as $post_data ) { | |
$post = [ | |
'post_category' => [ 7 ], | |
'post_title' => $post_data->title->rendered, | |
'post_status' => 'publish', | |
'post_date' => $post_data->date, | |
'post_content' => $post_data->content->rendered, | |
'post_excerpt' => $post_data->excerpt->rendered, | |
]; | |
wp_insert_post( $post, false ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment