1. Home
  2. Docs
  3. UniWP 1.5
  4. Posts class
  5. Get

Get

WHAT ISSearch for Posts with the given search criteria.
DONEReturn an array of Post objects. Each object contains details about the found Post.
ERRORReturn the WordPress system error message (see the WP Code Reference).
USED WP
METHODS
get_posts

_ = wpPosts.$Get$(%search%).$Done$(%doneCallback%).$Error$(%errorCallback%).$Run$();

search|Search
The search criteria to use for looking for WordPress’s Posts (see the Search paragraph below).
__
doneCallback|function
The function to call when the operation will be completed.
Note: the use of the Done() method is mandatory.
__
errorCallback|(function)
The function to call in case of error.
Note: the use of the Error() method is optional and can be omitted.

{{{#912c9a|WPReply|Data-type|Property or method description}}}
__
.GetPosts()|[array<Post>]
Return an array of Post objects (see the GetPosts() paragraph below).
__
.isOK|bool
true if everything is ok, false in case of error.
__
.isError|bool
true in case of error, false if everything is ok.
__
.error|string
The error message from the Server. It can be a string generated by WordPress through its get_error_message method (see the WP manual).
__
errorType|HttpRequest.Error Enum
The kind of error:
NONE = no error.
HTTP_ERROR = communication error.
SYSTEM_ERROR = UniWP error.
WORDPRESS_ERROR = error message from WordPress REST APIs.


Search

The search parameter must be a Search object containing the values to use for searching the Posts (see the WP manual for more information).

numberposts|int
Default: 5
A total number of posts to retrieve. Use a value of -1 to retrieve all the posts.
__
category|string
Category ID or comma-separated list of IDs (this or any children).
__
include|string
A comma-separated list of post IDs to retrieve, sticky posts will be included.
__
exclude|string
A comma-separated list of post IDs not to retrieve.
__
suppress_filters|bool
Default: true
Whether to suppress filters.
__
author__in|string
A comma-separated list of author IDs to query from.
__
category_name|string
The category slug (not name, this or any children).
__
name|string
Post slug.
__
offset|int
The number of posts to offset before retrieval.
__
order|string
Default: “DESC”
Designates ascending or descending order of posts. Accepts ‘ASC’, ‘DESC’.
__
orderby|string
Default: “date”
Sort retrieved posts by parameter.
__
post_parent__in|string
A comma-separated list of parent page IDs to query child pages from.
__
post_type|string
Default: “post”
A post type slug.
__
post_status|string
A post status.
__
tag_id|string
Tag id or comma-separated list of IDs.
__
includeContent|bool
Default: false
Include the Post content into the retrieved posts.
__
includeExcerpt|bool
Default: false
Include the Post excerpt into the retrieved posts.


GetPosts()

The GetPosts() method of the WPReply class returns an array of Post objects. Each object contains the found Post details (see the WP manual for more details).

ID|int
The Post’s ID.
__
post_author|string
The ID of the user who added the post.
__
post_date|string
The date of the post.
__
post_date_gmt|string
The date of the post in the GMT timezone.
__
post_content|string
The post content.
Note: only if the includeContent Search property is set to true.
__
post_title|string
The post title.
__
post_excerpt|string
The post excerpt.
Note: only if the includeExcerpt Search property is set to true.
__
post_status|string
The post status.
__
comment_status|string
Whether the post can accept comments. It can be ‘open’ or ‘closed’.
__
ping_status|string
Whether the post can accept pings. It can be ‘open’ or ‘closed’.
__
post_password|string
The password to access the post.
__
post_name|string
The post name. Default is the sanitized post title when creating a new post.
__
to_ping|string
Space or carriage return-separated list of URLs to ping. Default empty.
__
pinged|string
Space or carriage return-separated list of URLs that have been pinged.
__
post_modified|string
The date when the post was last modified. Default is the current time.
__
post_modified_gmt|string
The date when the post was last modified in the GMT timezone.
__
post_content_filtered|string
The filtered post content.
Note: only if the includeContent Search property is set to true.
__
post_parent|int
The ID of the post this post belongs to if any.
__
guid|string
Global Unique ID for referencing the post.
__
menu_order|int
The order the post should be displayed in.
__
post_type|string
The post type.
__
post_mime_type|string
The mime type of the post.
__
comment_count|string
The total comment counts for the post.
__
filter|string
The post object’s sanitization level.

var myPosts = new UniWP.Posts();

var search = new UniWP.Posts.Search 
{
    post_type = "page",
    numberposts = -1,
    order = "ASC",
    includeExcertp = true
}

_ = myPost.Get(search)
    .Done((WPReply reply) => 
    {
        if (reply.isOK) {

           var foundPosts = reply.GetPosts();

           foreach (var post in foundPosts) Debug.Log("Title: " + post.post_title); 

        }
    })
    .Error((WPReply reply) => 
    {
        Debug.LogError(reply.error);
    })
    .Run()