1. Go to this page and download the library: Download kaizencoders/wp-fluent 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/ */
kaizencoders / wp-fluent example snippets
// You can use the global wpFluent() function
$user = wpFluent()->table('users')->find(1);
// Or, create a connection using $wpdb, only once.
global $wpdb;
new \WpFluent\Connection($wpdb, ['prefix' => $wpdb->prefix], 'DB');
$user = DB::table('users')->find(3);
$query = DB::table('users')->where('display_name', 'LIKE', '%admin%');
// Get result
$query->get();
DB::registerEvent('before-select', 'posts', function ($qb) {
$qb->where('psot_status', '!=', 'draft');
});
// Get the global wpdb instance.
global $wpdb;
new \WpFluent\Connection($wpdb, ['prefix' => $wpdb->prefix], 'DB');
// Run query
$query = DB::table('my_table')->where('name', '=', 'admin');
// Or, simply use the global wpFluent() function.
// It handles all the ncessary initial setup.
wpFluent()->table('my_table')->where('name', '=', 'admin');
new \WpFluent\Connection($wpdb, ['prefix' => $wpdb->prefix], 'MyAlias');
$connection = new \WpFluent\Connection($wpdb, ['prefix' => $wpdb->prefix]);
$db = new \WpFluent\QueryBuilder\QueryBuilderHandler($connection);
$query = $db->table('my_table')->where('name', '=', 'admin');
var_dump($query->get());
DB::table('my_table')
->where('my_table.age', 10)
->where(function ($q) {
$q->where('name', 'LIKE', '%najrul%');
// You can provide a closure on these wheres too, to nest further.
$q->orWhere('description', 'LIKE', '%frost%');
});
DB::transaction(function ($qb) {
$qb->table('my_table')->insert(array(/* data... */));
$qb->commit(); // to commit the changes (data would be saved)
$qb->rollback(); // to rollback the changes (data would be rejected)
});