PHP code example of pollen-solutions / wp-database
1. Go to this page and download the library: Download pollen-solutions/wp-database 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/ */
pollen-solutions / wp-database example snippets
use Pollen\WpDatabase\Eloquent\User;
$users = User::on()->limit(10)->get();
try {
$data = json_encode($users->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;
use Pollen\WpDatabase\Eloquent\User;
$users = User::on()->with('metas')->limit(10)->get();
try {
$data = json_encode($users->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;
use Pollen\WpDatabase\Eloquent\User;
$users = User::on()->limit(10)->get();
try {
$data = json_encode($users->makeHidden(User::metaAttributes())->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;
use Pollen\WpDatabase\Eloquent\User;
$users = User::on()->with('posts')->find(1);
try {
$data = json_encode($users->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;
namespace App\Model;
use Pollen\WpDatabase\Eloquent\User;
class Administrator extends User
{
public $userRoleScope = 'administrator';
}
$admins = Administrator::on()->limit(10)->get();
try {
$data = json_encode($admins->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;
use Pollen\WpDatabase\Eloquent\User;
$users = User::on()->role('administrator')->limit(10)->get();
try {
$data = json_encode($users->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;
use Pollen\WpDatabase\Eloquent\User;
User::setBlogScope(2);
$users = User::on()->role('administrator')->limit(10)->get();
try {
$data = json_encode($users->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;
User::resetBlogScope();
use Pollen\WpDatabase\Eloquent\User;
$users = User::on()->blog(2)->limit(10)->get();
try {
$data = json_encode($users->toArray(), JSON_THROW_ON_ERROR);
} catch (\Throwable $e ) {
$data = $e->getMessage();
}
echo $data;