PHP code example of brw / wp-eloquent

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

    

brw / wp-eloquent example snippets




use WPEloquent\Database;

t();

// Advanced usage
Database::connect(
    [
        'driver'    => 'mysql',
        'prefix'    => 'wp_',
        'host'      => DB_HOST,
        'database'  => DB_NAME,
        'username'  => DB_USER,
        'password'  => DB_PASSWORD,
        'port'      => '3306',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
    ]
);



use WPEloquent\Models\Post;

$posts = Post::limit(10)->where('post_status', 'publish')->get();

foreach ($posts as $post) : 



use WPEloquent\Models\Post;

class CustomPostType extends Post
{
    /**
     * The post type for the model.
     *
     * @var array|string
     */
    $postType = 'custom_post_type';
}



use WPEloquent\Models\Model;

class CustomTable extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'custom_table';
}