Core Theme Components

ResultSet extends Countable

ResultSets provide a fluent interface to fetching data.

Table of Contents

__toString()  : string
addToCollection()  : void
Add the results directly to a collection.
asc()  : ResultSet
Set ordering to ASC.
cache()  : ResultSet
Sets the cache expires time in seconds. -1 is no cache, 0 is cache forever.
desc()  : ResultSet
Set ordering to DESC.
exclude()  : ResultSet
Excludes records by ID. If $parent is true, only parent IDs are excluded.
exists()  : bool
Returns true if record exists.
factory()  : ResultSet
Creates a ResultSet instance.
filter()  : ResultSet
Filter a query by keyword args. See WP_Query documentation for a full list of args.
first()  : array<string|int, mixed>
Retrieve only the first result. This method will hit the database.
get()  : array<string|int, mixed>
Returns the result set array based on the set query params.
ignoreStickyPosts()  : self
Ignore any settings for "sticky posts".
include()  : ResultSet
Includes records by ID.
latest()  : ResultSet
Retrieve the latest records by date.
limit()  : ResultSet
Sets the `posts_per_page` parameter.
order()  : ResultSet
Sets the `order` parameter. Default is `DESC`.
orderBy()  : ResultSet
Sets the `orderby` value.
page()  : ResultSet
Sets the `paged` parameter and sets `no_found_rows` to false.
pk()  : object|null
Retrieve the first result by primary key.
shuffle()  : array<string|int, mixed>
Shuffles (and slices) the result set. This method will hit the database.
slice()  : array<string|int, mixed>
Returns a slice of the collection starting at the given index.

Methods

__toString()

public __toString() : string
Return values
string

addToCollection()

Add the results directly to a collection.

public addToCollection(Collection &$collection[, mixed $key = null ]) : void
Parameters
$collection : Collection
$key : mixed = null
Return values
void

cache()

Sets the cache expires time in seconds. -1 is no cache, 0 is cache forever.

public cache(int $seconds) : ResultSet
Parameters
$seconds : int
Return values
ResultSet

exclude()

Excludes records by ID. If $parent is true, only parent IDs are excluded.

public exclude(array<string|int, mixed> $ids[, bool $parent = false ]) : ResultSet
Parameters
$ids : array<string|int, mixed>
$parent : bool = false
Return values
ResultSet

exists()

Returns true if record exists.

public exists(int $pk) : bool
Parameters
$pk : int
Return values
bool

factory()

Creates a ResultSet instance.

public static factory([string $postClass = '' ][, array<string|int, mixed> $params = [] ]) : ResultSet
Parameters
$postClass : string = ''
$params : array<string|int, mixed> = []
Return values
ResultSet

filter()

Filter a query by keyword args. See WP_Query documentation for a full list of args.

public filter(array<string|int, mixed> $params) : ResultSet
Parameters
$params : array<string|int, mixed>
Return values
ResultSet

first()

Retrieve only the first result. This method will hit the database.

public first() : array<string|int, mixed>
Return values
array<string|int, mixed>

get()

Returns the result set array based on the set query params.

public get() : array<string|int, mixed>

This method will hit the database.

Return values
array<string|int, mixed>

ignoreStickyPosts()

Ignore any settings for "sticky posts".

public ignoreStickyPosts() : self
Return values
self

include()

Includes records by ID.

public include(array<string|int, mixed> $ids) : ResultSet
Parameters
$ids : array<string|int, mixed>
Return values
ResultSet

limit()

Sets the `posts_per_page` parameter.

public limit(mixed $limit) : ResultSet
Parameters
$limit : mixed
Return values
ResultSet

order()

Sets the `order` parameter. Default is `DESC`.

public order([string $order = 'DESC' ]) : ResultSet
Parameters
$order : string = 'DESC'
Return values
ResultSet

page()

Sets the `paged` parameter and sets `no_found_rows` to false.

public page(int $num) : ResultSet
Parameters
$num : int
Return values
ResultSet

pk()

Retrieve the first result by primary key.

public pk(int $pk) : object|null
Parameters
$pk : int
Return values
object|null

shuffle()

Shuffles (and slices) the result set. This method will hit the database.

public shuffle(int $andSlice) : array<string|int, mixed>
Parameters
$andSlice : int
  • optional
Return values
array<string|int, mixed>

slice()

Returns a slice of the collection starting at the given index.

public slice(int $start) : array<string|int, mixed>

Similar to Laravel's slice(). This method will hit the database.

Parameters
$start : int
Return values
array<string|int, mixed>

Search results