1. Go to this page and download the library: Download ignitekit/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/ */
ignitekit / wp-orm example snippets
$db = \IgniteKit\WP\ORM\Eloquent\Database::instance();
var_dump( $db->table('users')->find(1) );
var_dump( $db->select('SELECT * FROM wp_users WHERE id = ?', [1]) );
var_dump( $db->table('users')->where('user_login', 'john')->first() );
// OR with DB facade
use \IgniteKit\WP\ORM\Eloquent\Facades\DB;
var_dump( DB::table('users')->find(1) );
var_dump( DB::select('SELECT * FROM wp_users WHERE id = ?', [1]) );
var_dump( DB::table('users')->where('user_login', 'john')->first() );
namespace Whatever;
use IgniteKit\WP\ORM\Eloquent\Model;
class CustomTableModel extends Model {
/**
* Name for table without prefix
*
* @var string
*/
protected $table = 'table_name';
/**
* Columns that can be edited - IE not primary key or timestamps if being used
*/
protected $fillable = [
'city',
'state',
'country'
];
/**
* Disable created_at and update_at columns, unless you have those.
*/
public $timestamps = false;
/** Everything below this is best done in an abstract class that custom tables extend */
/**
* Set primary key as ID, because WordPress
*
* @var string
*/
protected $primaryKey = 'ID';
/**
* Make ID guarded -- without this ID doesn't save.
*
* @var string
*/
protected $guarded = [ 'ID' ];
}
$users = $db->table('users')->get();
foreach ($users as $user) {
var_dump($user->display_name);
}
use \IgniteKit\WP\ORM\Eloquent\Model as Model;
class Employee extends Model {
}
var_dump( Employee::all()->toArray() ); // gets all employees
var_dump( Employee::find(1) ); // find employee with ID 1
use IgniteKit\WP\ORM\Models\Post as Post;
var_dump( Post::all() ); //returns only posts with WordPress post_type "post"
use IgniteKit\WP\ORM\Models\Post as Post;
var_dump(Post::type('page')->get()->toArray()); // get pages
var_dump(Post::status('publish')->get()->toArray()); // get posts with publish status
var_dump(Post::type('page')->status('publish')->get()->toArray()); // get pages with publish status
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.