WP-API / client-php

Reference client library for the WP API
Other
60 stars 17 forks source link

Edit of post does not work #9

Open maximilianredt opened 9 years ago

maximilianredt commented 9 years ago

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?

horllste commented 8 years ago

please where you able to fix this error?

thanks

maximilianredt commented 8 years ago

Nope, I wrote a wordpress plugin for my use case instead of using this plugin.

horllste commented 8 years ago

please can you help me with the code below, it is not posting or is your plugin available somewhere?

<?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 ); ?>

asefur commented 7 years ago

add this plugin https://github.com/WP-API/Basic-Auth