PHP code example of sultann / wp-query-builder
1. Go to this page and download the library: Download sultann/wp-query-builder 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/ */
sultann / wp-query-builder example snippets
$query = \PluginEver\QueryBuilder\Query::init();
$query = \PluginEver\QueryBuilder\Query::init('query_users');
$results = $query->select('*')
->from('users')
->get();
$results = $query->select('ID')
->from('users')
->get();
$results = $query->select('user_login, user_email')
->from('users')
->get();
$results = $query->select('*')
->from('users')
->where('user_email', 'like', '%gmail.com')
->get();
$results = $query->select('*')
->from('users')
->where('user_email', 'like', '%gmail.com')
->orWhere('user_email', 'like', '%yahoo.com')
->get();
$results = $query->select('*')
->from('posts')
->where('post_status', 'publish')
->where(function($q)
{
$q->where('menu_order', '>', 21);
$q->where('menu_order', '<', 99);
})
->orWhere('post_type', 'page')
->get();
$results = $query->select('*')
->from('posts')
->whereBetween('menu_order', 1, 20)
->get();
$results = $query->select('*')
->from('posts')
->whereNotBetween('menu_order', 20, 30)
->get();
$results = $query->select('*')
->from('posts')
->whereDateBetween('post_date', '2010-04-22 10:16:21', '2020-05-04')
->get();
$results = $query->select( '*' )
->from( 'posts p' )
->join( 'users u', 'u.ID', '=','p.post_author' )
->get();
$results = $query->select( '*' )
->from( 'posts p' )
->join( 'users u', 'u.ID', '=','p.post_author' )
->join('usermeta um', function($q) {
$q->where('um.meta_key', 'first_name');
$q->where('um.met_value', 'like', '%sultan%');
})
->get();
$results = $query->select('*')
->from('posts')
->group_by('post_status')
->get();
$results = $query->select('*')
->from('posts')
->group_by('post_status')
->having('count(ID)>1')
->get();
$results = $query->select('*')
->from('posts')
->order_by('post_title', 'DESC')
->get();
$results = $query->select('*')
->from('posts')
->limit(20, 10)
->get();
$results = $query->select('*')
->from('posts')
->limit(20)
->get();
$results = $query->select('*')
->from('posts')
->limit(20)
->offset(10)
->get();
$results = $query->select('*')
->from('posts')
->page(1, 20)//page number & page size
->get();
$results = $query->select('*')
->from('posts')
->find(1, 'ID');
$results = $query->select('*')
->from('posts')
->first();
$results = $query->select('*')
->from('posts')
->last();
$results = $query->select('*')
->from('posts')
->count();
$results = $query->from('posts as p')
->join('users as u', 'p.post_author', 'u.ID')
->join('usermeta um', function($q) {
$q->where('um.meta_key', 'first_name');
$q->where('um.met_value', 'like', '%sultan%');
})
->toSql();
$results = $query->table('posts')
->where('ID', 20)
->update(['post_title' => 'updated']);
$results = $query->from('posts')
->where('ID', 20)
->delete();
$results = $query->from('posts')
->search('Hello Word', array('post_title', 'post_content')) // it will search Hello & World both
->delete();