Forked originally from mattwilding/laravel-wp-api
Laravel 6+ package for the Wordpress JSON REST API, with support for MultiSite tenant management automation. Uses multisite-json-api on the WordPress side of things.
Simply add the following line to your composer.json
and run install/update:
"mainstreamct/laravel-wp-api": "~2.0"
You will need to add the service provider and optionally the facade alias to your config/app.php
:
'providers' => array(
MainstreamCT\WordPressAPI\WordPressAPIServiceProvider::class
)
'aliases' => array(
'WordPressAPI' => MainstreamCT\WordPressAPI\Facades\WordPressAPI::class
),
And publish the package config files to configure the location of your Wordpress install:
php artisan vendor:publish
Provide the following in your .env
file:
WP_API_ENDPOINT=your_site_name
WP_API_USERNAME=your_site_admin_username
WP_API_PASSWORD=your_site_admin_password
Don't forget to re-cache your configuration!
php artisan config:cache
The package provides a simplified interface to some of the existing api methods documented here.
You can either use the Facade provided or inject the MainstreamCT\WordPressAPI\WordPressAPI
class.
WordPressAPI::getPosts($page);
WordPressAPI::getPages($page);
WordPressAPI::getPostBySlug($slug);
WordPressAPI::getPostByID($id);
WordPressAPI::getCategories();
WordPressAPI::getTags();
WordPressAPI::getPostsByCategory($slug, $page);
WordPressAPI::getPostsByAuthor($slug, $page);
WordPressAPI::getPostsByTags($tags, $page);
WordPressAPI::searchPosts($query, $page);
WordPressAPI::getPostsByDate($year, $month, $page);
WordPressAPI::deploy($site_name, $blog_title, $email, $password);