PHP code example of dbout / wp-orm

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

    

dbout / wp-orm example snippets




use Dbout\WpOrm\Models\Post;
use Dbout\WpOrm\Models\User;

$post = Post::find(42);
$post = Post::findOneByName('hello-world');

$user = User::findOneByEmail('[email protected]');

use Dbout\WpOrm\Enums\PostStatus;
use Dbout\WpOrm\Models\Post;

$publishedPosts = Post::query()
    ->whereStatus(PostStatus::Publish)
    ->whereTypes('post', 'page')
    ->orderBy(Post::DATE, 'desc')
    ->limit(10)
    ->get();

use Dbout\WpOrm\Models\Post;

$post = new Post();
$post->setPostTitle('Hello world');
$post->setPostName('hello-world');
$post->setPostType('post');
$post->save();

$post->setPostTitle('Hello, again');
$post->save();

$post->setMeta('color', 'blue');
$value = $post->getMetaValue('color');     // 'blue'
$post->hasMeta('color');                    // true
$post->deleteMeta('color');

// Filter posts by meta value
Post::query()
    ->addMetaToFilter('color', 'blue')
    ->addMetaToSelect('size')
    ->get();

$post = Post::find(42);

$author = $post->author;        // BelongsTo User
$comments = $post->comments;    // HasMany Comment
$parent = $post->parent;        // BelongsTo Post (self)

> class SafeUser extends \Dbout\WpOrm\Models\User
> {
>     protected $fillable = [
>         self::LOGIN,
>         self::EMAIL,
>         self::DISPLAY_NAME,
>     ];
> }
>