wp_remote_post создать пост дважды - PullRequest
0 голосов
/ 20 марта 2019

Я поместил этот код в single.php только для проверки. После загрузки страницы в черновиках создаются два поста. Но в $ api_response я вижу только один созданный пост. В чем проблема? (Авторизация с плагином Пароли приложений)

<code>$api_response = wp_remote_post( 'https://example.com/wp-json/wp/v2/posts', array(
    'headers' => array(
        'Authorization' => 'Basic ' . base64_encode( 'testAdmin:DG4D 0KWq 81VO gSmB fTsM p2LF' )
    ),
    'body' => array(
        'title'   => 'Lorem ipsum dolor sit amet',
        'status'  => 'draft', // publish/draft
        'content' => 'Aenean nec ipsum at augue scelerisque finibus. Phasellus nec lorem iaculis, suscipit velit sed, blandit elit.',
//      'categories' => 5, // category ID
//      'tags' => '1,4,23', // string, comma separated
//      'date' => '2015-05-05T10:00:00', // YYYY-MM-DDTHH:MM:SS
        'excerpt' => 'Aenean nec ipsum at augue scelerisque finibus.',
//      'password' => '12$45',
        'slug' => 'lorem-ipsum', // part of the URL usually
        // more body params are here:
        // developer.wordpress.org/rest-api/reference/posts/#create-a-post
    )
) );
$body = json_decode( $api_response['body'] );

if( wp_remote_retrieve_response_message( $api_response ) === 'Created' ) {
    echo 'The post "' . $body->title->rendered . '" has been created successfully';
}

echo "<pre>";
print_r( $body );
echo "
";
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...