PHP code example of angelxmoreno / wprestclient

1. Go to this page and download the library: Download angelxmoreno/wprestclient library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

angelxmoreno / wprestclient example snippets


    use WPRestClient\Core\ApiClient;
    
    $client = new ApiClient('https://example.com');
    

    $posts = $client->sendRequest('get','/posts');
    foreach ($posts as $post) {
        echo $post['title']['rendered'];
    }
    

   use WPRestClient\Repository\PostsRepositor;
   
   PostsRepository::setApiClient($client);
   $posts = PostsRepository::fetch();
   foreach ($posts as $post) {
       echo $post->getTitle();
   }
    

   use WPRestClient\Repository\PagesRepository;
   use WPRestClient\Core\RepositoryRegistry;
   use WPRestClient\Entity\PageEntity;
   
   $registry = new RepositoryRegistry($client);
   $page = new PageEntity(['title' => 'A New Page']);
   $registry->pages()->create($page);
    

   use WPRestClient\Repository\PagesRepository;
   use WPRestClient\Core\RepositoryRegistry;
   use WPRestClient\Entity\PageEntity;
   
   $registry = new RepositoryRegistry($client);
   $post = $registry->posts()->get(123);
   $registry->posts()->delete($post);