Skip to content

Query Builder

Ale Mostajo edited this page Jun 26, 2020 · 2 revisions

The QueryBuilder class allows to build up a query using its methods. It uses $wpdb in its core to build and execute the queries.

Global function

Start using the query builder by calling the global function wp_query_builder():

$builder = wp_query_builder();

This will return an instance of TenQuality\WP\Database\QueryBuilder ready to be used.

Instantiate class

Alternatively, in order to use the class directly, this must be instantiated into a variable; requires to use php's use statement at the beginning of the script:

use TenQuality\WP\Database\QueryBuilder;

With constructor

Default:

$builder = new QueryBuilder();

Using an ID to identify the query (which can be later use for wordpress hooks):

$builder = new QueryBuilder( 'my_query' );

With static constructor

Default:

$builder = QueryBuilder::create();

Using an ID:

$builder = QueryBuilder::create( 'my_query' );
Clone this wiki locally