Skip to content

Collections Reference

This reference page documents in detail the collections added to an Astro project by DeWP’s collection loaders.

Data structure

Each collection corresponds to one of WordPress’s data types available from the WordPress REST API and in general matches the schema of those endpoints.

One important difference between the JSON responses returned by the REST API and DeWP’s content collections is that references between collections are encoded as Astro collection references instead of as raw integers. This simplifies looking up related entries using Astro’s getEntry() and getEntries() functions.

For example, post data contains an array specifying the categories that post belongs to. You can turn that array of references into a fully resolved array of category data using getEntries():

import { getEntry, getEntries } from 'astro:content';
const myFirstPost = await getEntry('posts', '1');
// [{ id: '1', data: { name: 'Hello world!', categories: [{ id: '1', collection: 'categories' }], ... } }]
const categories = await getEntries(myFirstPost.data.categories);
// [{ id: '1', data: { name: 'Uncategorized', ... } }]

Collections

Using wpCollections() in your content configuration adds the following content collections to your Astro project.

posts

The posts collection contains entries from WordPress’s wp/v2/posts endpoint. These are the blog posts and include fully rendered post content.

Example usage

example-post.astro
---
import { getEntry, render } from 'astro:content';
const post = await getEntry('posts', '1');
// post = {
// id: '1',
// collection: 'posts',
// data: {
// title: { rendered: 'Hello world!' },
// date: Wed Jun 04 2008
// // ...
// },
// ...
// }
const { Content } = render(post);
---
<h1 set:html={post.data.title.rendered} />
<Content />

Entry data

author

A reference to the author of the post.

categories

Type: array

The terms assigned to the post in the category taxonomy as an array of references.

comment_status

Type: "open" | "closed" | ""

Whether or not comments are open on the post.

content

Type: { rendered: string; protected: boolean }

The content for the post.

date

Type: string

The date the post was published, in the site's timezone.

date_gmt

Type: string

The date the post was published, as GMT.

excerpt

Type: { rendered: string; protected: boolean }

The excerpt for the post.

featured_media

A reference to the featured media for the post.

format

Type: "standard" | "aside" | "chat" | "gallery" | "link" | "image" | "quote" | "status" | "video" | "audio" | ""

The format for the post.

guid

Type: { rendered: string }

The globally unique identifier for the post.

id

Type: number

Unique identifier for the post.

link

Type: string

URL to the post.

meta

Meta fields object or array.

modified

Type: string

The date the post was last modified, in the site's timezone.

modified_gmt

Type: string

The date the post was last modified, as GMT.

ping_status

Type: "open" | "closed" | ""

Whether or not the post can be pinged.

slug

Type: string

An alphanumeric identifier for the post unique to its type.

status

Type: string

A named status for the post.

sticky

Type: boolean

Whether or not the post should be treated as sticky.

tags

Type: array

The terms assigned to the post in the post_tag taxonomy as an array of references.

template

Type: string

The theme file to use to display the post.

title

Type: { rendered: string }

The title for the post.

type

Type: string

Type of post.

pages

The pages collection contains content from WordPress’s wp/v2/pages endpoint. Pages include fully rendered content.

Unlike posts, pages are hierarchical and one page can have a parent page, allowing for the creation of tree-like page relationships.

Example usage

example-page.astro
---
import { getEntry, render } from 'astro:content';
const page = await getEntry('pages', '49');
const { Content } = render(page);
// Get the parent page if there is one:
const parent = page.data.parent && await getEntry(page.data.parent);
---
<h1 set:html={page.data.title.rendered} />
<Content />
{parent && (
<p>
This page is a child of <span set:html={parent.data.title.rendered} />
</page>
)}

Entry data

author

A reference to the author of the page.

comment_status

Type: "open" | "closed" | ""

Whether or not comments are open on this page.

content

Type: { rendered: string; protected: boolean }

The content for the page.

date

Type: string

The date the page was published, in the site's timezone.

date_gmt

Type: string

The date the page was published, as GMT.

excerpt

Type: { rendered: string; protected: boolean }

The excerpt for the page.

featured_media

A reference to the featured media for the post.

guid

Type: { rendered: string }

The globally unique identifier for the page.

id

Type: number

Unique identifier for the page.

link

Type: string

URL to the page.

menu_order

Type: number

The order of the page in relation to other pages.

meta

Meta fields.

modified

Type: string

The date the page was last modified, in the site's timezone.

modified_gmt

Type: string

The date the page was last modified, as GMT.

parent

A reference to a parent page.

ping_status

Type: "open" | "closed" | ""

Whether or not the page can be pinged.

slug

Type: string

An alphanumeric identifier for the page unique to its type.

status

Type: "publish" | "future" | "draft" | "pending" | "private"

A named status for the page.

template

Type: string

The theme file to use to display the page.

title

Type: { rendered: string }

The title for the page.

type

Type: string

Type of page.

categories

The categories collection contains entries from WordPress’s wp/v2/categories endpoint. Entries in the posts collection can contain references to categories. Metadata about individual categories such as their name, description, and number of posts are stored in the categories collection.

Entry data

count

Type: number

Number of published posts for the term.

description

Type: string

HTML description of the term.

id

Type: number

Unique identifier for the term.

link

Type: string

URL of the term.

meta

Meta fields.

name

Type: string

HTML title for the term.

parent

A reference to a parent category.

slug

Type: string

An alphanumeric identifier for the term unique to its type.

taxonomy

Type: string

Type attribution for the term.

tags

The tags collection contains entries from WordPress’s wp/v2/tags endpoint. Entries in the posts collection can contain references to tags. Metadata about individual tags such as their name, description, and number of posts are stored in the tags collection.

Entry data

count

Type: number

Number of published posts for the term.

description

Type: string

HTML description of the term.

id

Type: number

Unique identifier for the term.

link

Type: string

URL of the term.

meta

Meta fields.

name

Type: string

HTML title for the term.

slug

Type: string

An alphanumeric identifier for the term unique to its type.

taxonomy

Type: string

Type attribution for the term.

users

The users collection contains users from WordPress’s wp/v2/users endpoint.

Entry data

avatar_urls

Type: Record<string, string>

Avatar URLs for the user.

description

Type: string

Description of the user.

id

Type: number

Unique identifier for the user.

link

Type: string

Author URL of the user.

meta

Meta fields.

name

Type: string

Display name for the user.

slug

Type: string

An alphanumeric identifier for the user.

url

Type: string

URL of the user.

comments

The comments collection contains user comments from WordPress’s wp/v2/comments endpoint.

Entry data

author

A reference to the author of the comment, if author was a user.

author_avatar_urls

Type: Record<string, string>

Avatar URLs for the comment author.

author_name

Type: string

Display name for the comment author.

author_url

Type: string

URL for the comment author.

content

Type: { rendered: string }

The content for the comment.

date

Type: string

The date the comment was published, in the site's timezone.

date_gmt

Type: string

The date the comment was published, as GMT.

id

Type: number

Unique identifier for the comment.

link

Type: string

URL to the comment.

meta

Meta fields.

parent

A reference to a parent comment.

post

A reference to the associated post.

status

Type: string

State of the comment.

type

Type: string

Type of the comment.

media

The media collection contains media attachments from WordPress’s wp/v2/media endpoint.

Entry data

alt_text

Type: string

Alternative text to display when attachment is not displayed.

author

A reference to the author of the post.

caption

Type: { rendered: string }

The attachment caption.

comment_status

Type: "open" | "closed" | ""

Whether or not comments are open on the post.

date

The date the item was published, in the site's timezone.

date_gmt

The date the post was published, as GMT.

description

Type: { rendered: string }

The attachment description.

guid

Type: { rendered: string }

The globally unique identifier for the item.

id

Type: number

Unique identifier for the item.

link

Type: string

URL to the media item.

media_details

An object containing details about the media file, specific to its type.

media_type

Type: "image" | "file"

Attachment type.

meta

Meta fields.

mime_type

Type: string

The attachment MIME type.

modified

Type: string

The date the item was last modified, in the site's timezone.

modified_gmt

Type: string

The date the item was last modified, as GMT.

ping_status

Type: "open" | "closed" | ""

Whether or not the post can be pinged.

post

The ID for the associated post of the attachment.

slug

Type: string

An alphanumeric identifier for the item unique to its type.

source_url

Type: string

URL to the original attachment file.

status

Type: "publish" | "future" | "draft" | "pending" | "private" | "inherit"

A named status for the item.

template

Type: string

The theme file to use to display the post.

title

Type: { rendered: string }

The title for the post.

type

Type: string

Type of item.

statuses

The statuses collection contains status definitions from WordPress’s wp/v2/statuses endpoint.

Entry data

date_floating

Type: boolean

Whether posts of this status may have floating published dates.

id

Type: string

Unique identifier for this status definition.

name

Type: string

The title for the status.

public

Type: boolean

Whether posts of this status should be shown in the front end of the site.

queryable

Type: boolean

Whether posts with this status should be publicly-queryable.

slug

Type: string

An alphanumeric identifier for the status.

taxonomies

The taxonomies collection contains taxonomy definitions from WordPress’s wp/v2/taxonomies endpoint.

Entry data

description

Type: string

A human-readable description of the taxonomy.

hierarchical

Type: boolean

Whether or not the taxonomy should have children.

id

Type: string

Unique identifier for this taxonomy definition.

name

Type: string

The title for the taxonomy.

rest_base

Type: string

REST base route for the taxonomy.

rest_namespace

Type: string
Default: "wp/v2"

REST namespace route for the taxonomy.

slug

Type: string

An alphanumeric identifier for the taxonomy.

types

Type: array

Types associated with the taxonomy.

types

The types collection contains post type definitions from WordPress’s wp/v2/types endpoint.

Entry data

description

Type: string

A human-readable description of the post type.

has_archive

Type: boolean | string
Default: false

If the value is a string, the value will be used as the archive slug. If the value is false the post type has no archive.

hierarchical

Type: boolean

Whether or not the post type should have children.

icon

Type: string | null
Default: null

The icon for the post type.

id

Type: string

A unique identifier for the post type.

name

Type: string

The title for the post type.

rest_base

Type: string

REST base route for the post type.

rest_namespace

Type: string
Default: "wp/v2"

REST route's namespace for the post type.

slug

Type: string

An alphanumeric identifier for the post type.

taxonomies

Type: array

site-settings

The site-settings collection contains a single entry with some basic configuration options exposed by WordPress.

Example usage

The easiest way to load site settings is with DeWP’s getSiteSettings utility:

import { getSiteSettings } from 'dewp/content-utils';
const settings = await getSiteSettings();

Entry data

description

Type: string

A human-readable description of the site.

gmt_offset

Type: number

The site's timezone expressed as an offset in hours from GMT

home

Type: string

The URL of the site homepage. (Usually the same as `url`.)

id

Type: string
Default: "settings"

name

Type: string

The site title.

site_icon

Reference to a media attachment to use as the site icon.

site_icon_url

Type: string

URL to a resource to use as the site icon.

site_logo

Reference to a media attachment to use as the site logo.

timezone_string

Type: string

The site's timezone as a string, e.g. `"Europe/Paris"`.

url

Type: string

The URL of the site.