mehedimi / wp-query-builder-ext
An Extension of WP Query Builder
Installs: 24
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/mehedimi/wp-query-builder-ext
Requires
Requires (Dev)
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.4
README
WP Query Builder Extension
This is an extension of WP Query Builder.
Installation
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.
Relations
WithTaxonomy
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();
Plugins
JoinPostWithMeta
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()