client-php
client-php copied to clipboard
Edit of post does not work
Hi,
I've tried to update a post via:
$post = $api->posts->create(
array(
'title' => 'Test Article ' . date('c'),
'content_raw' => 'Test Article Description ' . date('c'),
'date' => date('c', time()),
'status' => 'publish',
'comment_status' => 'closed'
)
);
var_dump($post);
$ret = $post->update(
array(
'title' => 'Test Article Updated ' . date('c'),
'content_raw' => 'Test Article Description Updated ' . date('c'),
)
);
var_dump($ret);
I get the following error:
PHP Fatal error: Uncaught exception 'Requests_Exception_HTTP_412' with message '412 Precondition Failed' in [...]vendor/rmccue/requests/library/Requests/Response.php:92
Any ideas why?
Thanks!
EDIT:
When I debug the Request it looks like the API throws up the following error:
There is a revision of this post that is more recent.
Which does not really make sense, because I just added the entry two lines earlier, does it?
please where you able to fix this error?
thanks
Nope, I wrote a wordpress plugin for my use case instead of using this plugin.
please can you help me with the code below, it is not posting or is your plugin available somewhere?
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 ); ?>
add this plugin https://github.com/WP-API/Basic-Auth