PHPackages                             twork/query - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. twork/query

ActiveLibrary[Database &amp; ORM](/categories/database)

twork/query
===========

A WP\_Query wrapper.

2.3.0(4y ago)11571MITPHPPHP ^7.1

Since Nov 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Tsquare17/Twork-Query)[ Packagist](https://packagist.org/packages/twork/query)[ RSS](/packages/twork-query/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (3)Versions (6)Used By (1)

Twork Query
===========

[](#twork-query)

A WordPress WP\_Query wrapper.
------------------------------

[](#a-wordpress-wp_query-wrapper)

### Installation

[](#installation)

- composer require twork/query

### Example Usage:

[](#example-usage)

```
use Twork\Query\Query;

$query = new Query('custom-post');

$query->author('Jim')
    ->category('tech')
    ->postsPerPage(20);

foreach ($query as $postId) {
    the_title();
}
```

In the above example, a query is created for custom-post post types, where the author is Jim, and the category is tech, with a maximum of 20 posts per page.

Alternatively, $query-&gt;fetch() can be used, which returns a generator that wraps the WP loop. It will yield either null, or an object, if a class is supplied as an argument.

```
use Twork\Query\Query;

$query = new Query();

foreach ($query->fetch() as $null) {
    the_title();
}
```

```
