Post class.

Since

2.0.0

Type Parameters

Hierarchy (view full)

Constructors

Properties

_searchTerm: string = ''
_slug: string = ''
endpoint: string = 'posts'
_instance: WPJSSingleton

Methods

  • Set the author.

    Parameters

    • userId: number

    Returns this

    Since

    2.0.0

    Description

    This will set the author. This is useful if you want to get posts from different authors while keeping the same Post instance.

    Example

    import {Post} from "@quickdevelopment/wp-js";

    const authorPosts = new Post();

    authorPosts.byAuthor(1).fetch().then((posts) => {
    // This will return the posts from author with id 1.
    console.log(posts)
    })
  • Set the searchTerm.

    Parameters

    • searchTerm: string

    Returns this

    Since

    2.0.0

    Description

    This will set the searchTerm. This is useful if you want to get posts from different searchTerms while keeping the same Post instance.

    Example

    import {Post} from "@quickdevelopment/wp-js";

    const searchTermPosts = new Post();

    searchTermPosts.bySearchTerm('hello-world').fetch().then((posts) => {
    // This will return the post from search term 'hello-world'.
    console.log(posts)
    })
  • Set the slug.

    Parameters

    • slug: string

    Returns this

    Since

    2.0.0

    Description

    This will set the slug. This is useful if you want to get posts from different slugs while keeping the same Post instance.

    Example

    import {Post} from "@quickdevelopment/wp-js";

    const slugPost = new Post();

    slugPost.bySlug('hello-world').fetch().then((post) => {
    // This will return the post from slug 'hello-world'.
    console.log(post)
    })
  • Get a single post.

    Returns Promise<T | T[]>

    Since

    2.0.0

    Example

    import {Post} from "@quickdevelopment/wp-js";

    const post = new Post('posts/1');

    post.fetch().then((post) => {
    console.log(post)
    })
  • Protected

    Fetch multiple objects from the endpoint.

    Returns Promise<T[]>

    Since

    2.0.0

  • Protected

    Get data about the current class.

    Type Parameters

    • T

    Returns Promise<T>

    Since

    1.0.0

  • Protected

    Get the search parameters.

    Returns URLSearchParams

  • Get the searchTerm.

    Returns string

    Since

    2.0.0

  • Get the slug.

    Returns string

    Since

    2.0.0

  • Set the amount of posts to take.

    Parameters

    • perPage: number
    • page: number

    Returns this

    Since

    2.0.0

    Description

    This will paginate the posts using per_page and the page query parameters.

  • Set search parameters for the request.

    Parameters

    • params: Record<string, string | number>

      Object containing search parameters.

    Returns this

    Since

    2.0.0

Generated using TypeDoc