mixins/parameters

Filter methods that can be mixed in to a request constructor's prototype to allow that request to take advantage of top-level query parameters for collection endpoints. These are most relevant to posts, pages and CPTs, but pagination helpers are applicable to any collection.

Mixins

parameters

Methods

(inner) after(date)

Retrieve only records published after a specified date

Source:
Parameters:
Name Type Description
date String | Date

An ISO 8601-compliant date string, or Date object

Returns:

The request instance (for chaining)

Examples

Provide an ISO 8601-compliant date string

    wp.posts().after('1986-03-22')...

Provide a JavaScript Date object

    wp.posts().after( new Date( 1986, 03, 22 ) )...

(inner) author(author)

Query for posts by a specific author. This method will replace any previous 'author' query parameters that had been set.

Note that this method will either set the "author" top-level query parameter, or else the "author_name" filter parameter (when querying by nicename): this is irregular as most parameter helper methods either set a top level parameter or a filter, not both.

Usage with the author nicename string is deprecated. Query by author ID instead. If the "rest-filter" plugin is not installed, the name query will have no effect.

Source:
Parameters:
Name Type Description
author String | Number

The nicename or ID for a particular author

Returns:

The request instance (for chaining)

(inner) before(date)

Retrieve only records published before a specified date

Source:
Parameters:
Name Type Description
date String | Date

An ISO 8601-compliant date string, or Date object

Returns:

The request instance (for chaining)

Examples

Provide an ISO 8601-compliant date string

    wp.posts().before('2016-03-22')...

Provide a JavaScript Date object

    wp.posts().before( new Date( 2016, 03, 22 ) )...

(inner) categories(categories)

Retrieve only records associated with one of the provided categories

Source:
Parameters:
Name Type Description
categories String | Number | Array

A term ID integer or numeric string, or array thereof

Returns:

The request instance (for chaining)

(inner) excludeCategories(category)

Exclude records associated with any of the provided category IDs

Source:
Parameters:
Name Type Description
category String | Number | Array

A term ID integer or numeric string, or array thereof

Returns:

The request instance (for chaining)

(inner) excludeTags(category)

Exclude records associated with any of the provided tag IDs

Source:
Parameters:
Name Type Description
category String | Number | Array

A term ID integer or numeric string, or array thereof

Returns:

The request instance (for chaining)

(inner) parent(parentId)

Search for hierarchical taxonomy terms that are children of the parent term indicated by the provided term ID

Source:
Parameters:
Name Type Description
parentId Number

The ID of a (hierarchical) taxonomy term

Returns:

The request instance (for chaining)

Example
wp.pages().parent( 3 ).then(function( pages ) {
      // console.log( 'all of these pages are nested below page ID#3:' );
      // console.log( pages );
    });

    wp.categories().parent( 42 ).then(function( categories ) {
      console.log( 'all of these categories are sub-items of cat ID#42:' );
      console.log( categories );
    });

(inner) password(password)

Specify the password to use to access the content of a password-protected post

Source:
Parameters:
Name Type Description
password string

A string password to access protected content within a post

Returns:

The request instance (for chaining)

(inner) post(post)

Specify the post for which to retrieve terms (relevant for e.g. taxonomy and comment collection endpoints).

Source:
Parameters:
Name Type Description
post String | Number

The ID of the post for which to retrieve terms

Returns:

The request instance (for chaining)

(inner) status(status)

Specify for which post statuses to return posts in a response collection

See https://codex.wordpress.org/Post_Status -- the default post status values in WordPress which are most relevant to the API are 'publish', 'future', 'draft', 'pending', 'private', and 'trash'. This parameter also supports passing the special value "any" to return all statuses.

Source:
Parameters:
Name Type Description
status string | Array.<string>

A status name string or array of strings

Returns:

The request instance (for chaining)

(inner) sticky(sticky)

Specify whether to return only, or to completely exclude, sticky posts

Source:
Parameters:
Name Type Description
sticky boolean

A boolean value for whether ONLY sticky posts (true) or NO sticky posts (false) should be returned in the query

Returns:

The request instance (for chaining)

(inner) tag(tag)

Legacy wrapper for .categories() that uses ?filter to query by slug if available

Deprecated:
  • Use `.categories()` and query by category IDs
Source:
Parameters:
Name Type Description
tag String | Number | Array

A category term slug string, numeric ID, or array of numeric IDs

Returns:

The request instance (for chaining)

(inner) tag(tag)

Legacy wrapper for .tags() that uses ?filter to query by slug if available

Deprecated:
  • Use `.tags()` and query by term IDs
Source:
Parameters:
Name Type Description
tag String | Number | Array

A tag term slug string, numeric ID, or array of numeric IDs

Returns:

The request instance (for chaining)

(inner) tags(tags)

Retrieve only records associated with one of the provided tag IDs

Source:
Parameters:
Name Type Description
tags String | Number | Array

A term ID integer or numeric string, or array thereof

Returns:

The request instance (for chaining)