lyfter/wp-query-builder

There is no license information available for the latest version (1.0.0) of this package.

1.0.0 2024-04-23 18:50 UTC

This package is auto-updated.

Last update: 2025-06-23 21:07:06 UTC


README

A package that allows you to create WP_Queries in a more elegant while offering you autocompletion in you IDE. Heavily inspired by Laravel Elequent and query builder.

Replace

$query = new WP_Query([
    'posts_per_page' => 5,
    'post_type' => 'page'
]);

$query->get_posts();

With

WpQuery::build()
    ->type('page')
    ->limit(5)
    ->get();

Installation

Install with composer

Run the following in your terminal to install the package with Composer.

$ composer require lyfter/wp-query-builder

The package uses PSR-4 autoloading and can be used with the Composer's autoloader. Below is a basic example of getting started, though your setup may be different depending on how you are using Composer.

require __DIR__ . '/vendor/autoload.php'; // Not required when using bedrock

use Lyfter\QueryBuilder\WpQuery;

$posts = WpQuery::build()
    ->type(['post', 'page'])
    ->limit(5)
    ->get();

See Composer's basic usage guide for details on working with Composer and autoloading. basic usage guide for details on working with Composer and autoloading.