使用WP API发布到WordPress"代码问题"

时间:2015-12-20 13:39:44

标签: php wordpress wordpress-plugin

我正在尝试使用WP API发布到WordPress网站。我有下面的代码,但它似乎没有工作,我的网站没有收到任何帖子。

<?php
$options  = array (
  'http' =>
  array (
    'ignore_errors' => true,
    'method' => 'POST',
    'header' =>
    array (
    'Authorization' => 'Basic ' . base64_encode( 'user' . ':' . 'pass' ),
    ),
    'content' =>
     http_build_query(  array (
        'title' => 'Hello World',
        'content' => 'Hello. I am a test post. I was created by the API',
        'tags' => 'tests',
        'categories' => 'API',
      )),
  ),
);

$context  = stream_context_create( $options );
$response = file_get_contents(
    'http://freeglobaljob.com/wp-json/posts/',
    false,
    $context
);
$response = json_decode( $response );
?>

0 个答案:

没有答案