PHP code example of mam4dali / laravel-wp-api

1. Go to this page and download the library: Download mam4dali/laravel-wp-api 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/ */

    

mam4dali / laravel-wp-api example snippets



'providers' => array(

mam4dali\LaravelWpApi\ServiceProvider::class

)

  

'aliases' => Facade::defaultAliases()->merge([

'WpApi' => mam4dali\LaravelWpApi\Facade::class,

])->toArray(),



$wp_api = new WpApi('http://localhost/wp/wp-json/wp/v2/', new \GuzzleHttp\Client(), null);

$jwt_token = $wp_api->jwtTokenGenerate('username', 'password');

$wp_api->SetJwtToken($jwt_token['token']);

$get_post = $wp_api->postId(1);



$wp_api->posts($page);

  



$wp_api->pages($page);

  



$wp_api->post($slug);

  



$wp_api->postId($id);

  



$wp_api->categories();

  



$wp_api->tags();

  



$wp_api->categoryPosts($slug, $page);

  



$wp_api->authorPosts($slug, $page);

  



$wp_api->tagPosts($slug, $page);

  



$wp_api->search($query, $page);

  



$wp_api->archive($year, $month, $page);