This is an extension of WP Query Builder.
It is a composer package. You can install it using composer by executing following composer command.
composer require mehedimi/wp-query-builder-ext
It has some relations and plugins of WP Query Builder.
With this relation you will be able to load associative taxonomies of specific posts.
// Retrieve all posts with associative taxonomies.
DB::table('posts')
->withRelation(new WithTaxonomy('taxonomies'))
->get()
If you need group by taxonomy type then just call groupByTaxonomy
method on WithTaxonomy
relation.
// Retrieve all posts with associative taxonomies group by with its type.
DB::table('posts')
->withRelation(new WithTaxonomy('taxonomies'), function(WithTaxonomy $taxonomy){
$taxonomy->groupByTaxonomy()
})
->get();
Optionally you add constrain of taxonomy type by calling taxonomy
method of WithTaxonomy
relation.
// This will fetch only category type of taxonomy.
DB::table('posts')
->withRelation(new WithTaxonomy('categories'), function(WithTaxonomy $taxonomy){
$taxonomy->taxonomy('category');
})->get();
With this plugin, you will be able to join postmeta
table with posts
very easily.
You need to just apply that plugin and that's it.
Some examples are given below:
DB::plugin(new JoinPostWithMeta())->select('posts.*')->where('meta_key', 'some meta key name')->get()
You could supply the join type on JoinPostWithMeta
class constructor as well.
// For joining right join `postmeta` with `posts` table
DB::plugin(new JoinPostWithMeta('right'))->select('posts.*')->where('meta_key', 'some meta key name')->get()