mehedimi/wp-query-builder-ext

An Extension of WP Query Builder

0.3 2024-02-11 00:53 UTC

This package is auto-updated.

Last update: 2024-11-16 14:26:57 UTC


README

WP Query Builder Extension Banner

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()