PHP code example of tradzero / wp_rest_laravel

1. Go to this page and download the library: Download tradzero/wp_rest_laravel 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/ */

    

tradzero / wp_rest_laravel example snippets


'providers' => [
    // Other service providers...
    Tradzero\WPREST\WPRESTServiceProvider::class,
],

'aliases' => [
    'WPREST' => Tradzero\WPREST\Facade::class,
]

use Tradzero\WPREST\Resources\Post;
use Tradzero\WPREST\Resources\Category;
use WPREST;

$post = new Post();
$post->setTitle('hello world');
$post->setContent('Its post created using WP REST API');

WPREST::createPost($post);

$post->setId('XX');
WPREST::updatePost($post);

$category = new Category;
$category->setName('category 1');
WPREST::findCategoryOrCreate($category);
// or
WPREST::createCategory($category);
$post->setCategories(array($category));
WPREST::createPost($post);
bash
$ php artisan vendor:publish --provider=Tradzero\WPREST\WPRESTServiceProvider