getDefaultPosts($fields)

Get an array of the default posts for the page. Equivilent to calling WP’s get_posts() without any arguments, except with more control over which fields are returned.

Usage

site()->getDefaultPosts($fields);

Parameters

ParameterTypeRequiredDescription
$fieldsarrayNoPost fields

Returns

TypeDescription
arrayIf fields were provided, values will be returned under those keys. Otherwise, only a post (WP_Post) and meta (array) field will be returned for each post.

Example

Using getDefaultPosts to get a list of vehicles, called from the archive page archive-vehicle.php.

site()->getDefaultPosts([
  'title',
  'id',
  'acf.price'
]);

// Returns
[
    [
        "title" => "2010 Ferrari 458 Italia",
        "id" => 170,
        "price" => 205000
    ],
    [
        "title" => "2019 Renault Alpine A110 L├ęgende GT",
        "id" => 163,
        "price" => 68700
    ],
    [
        "title" => "2019 MINI Cooper S 2-Door Hardtop",
        "id" => 109,
        "price" => 30129
    ],
    [
        "title" => "2019 FIAT 124 Spider Abarth",
        "id" => 102,
        "price" => 27200
    ],
    ... // And more
]