Post wrapper class.
This class wrap a WP_Post object and give them some helpers and some features like featured_image_url($size), accessor like featured_image_url, categories, authors, etc...
$post = new \WPS\Post($wp_post);
$post_id = $post->id;
$authors = $post->authors;
$featured_image_url = $post->featured_image_url('large');
$date = $post->date();Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Construct the object using the passed wp_post
| Name | Type | Description | Status | Default |
|---|---|---|---|---|
| $wp_post | { WP_Post } | The wordpress post object to encapsulate | required |
$wpsPost = new \WPS\Post($wp_post);Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
The post id
Type : { Integer }
Public
Default : null
The post name
Type : { String }
Public
Default : null
The post type
Type : { String }
Public
Default : null
The post date
Type : { String }
Public
Default : null
The post GMT date
Type : { String }
Public
Default : null
The post status
Type : { String }
Public
Default : null
The post comment status
Type : { String }
Public
Default : null
The post ping status
Type : { String }
Public
Default : null
The post password
Type : { String }
Public
Default : null
The post parent id
Type : { Integer }
Public
Default : null
The post modified datetime
Type : { String }
Public
Default : null
The post modified datetime GMT
Type : { String }
Public
Default : null
The post comment count
Type : { Integer }
Public
Default : 0
The post menu order
Type : { Integer }
Public
Default : null
The post permalink
Type : { String }
Public
Default : null
The post title with the filters applied
Type : { String }
Public
Default : null
The post raw title
Type : { String }
Public
Default : null
The post excerpt with the filters applied
Type : { String }
Public
Default : null
The post raw excerpt
Type : { String }
Public
Default : null
The post content with the filters applied
Type : { String }
Public
Default : null
The post raw content
Type : { String }
Public
Default : null
Get the post comments
Type : { Array<WP_Comment> }
$comments = $post->comments;Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Properties accessor
Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post format
Return { String , Boolean } The post format or false if not specified
$format = $post->format;Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post featured image url
Return { String } The post featured image url
$url = $post->featured_image_url;Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post featured image url
| Name | Type | Description | Status | Default |
|---|---|---|---|---|
| $size | { String } | The size wanted | optional | "full" |
Return { String } The post featured image url
$url = $post->featured_image_url('full');Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post categories
Return { Array } The post categories
$categories = $post->categories;Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post categories formated
| Name | Type | Description | Status | Default |
|---|---|---|---|---|
| $glue | { String } | The character used to glue together the categories | optional | ", " |
| $link | { Boolean } | If want a link around each categories or not | optional | true |
Return { String } The post categories formated
$categories = $post->categories(', ', true);Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post authors
Return { Array<WPS_User> } The post authors
$authors = $post->authors;Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post authors formated
| Name | Type | Description | Status | Default |
|---|---|---|---|---|
| $glue | { String } | The character used to glue together the authors | optional | ", " |
| $link | { Boolean } | If want a link around each authors or not | optional | true |
Return { String } The post authors
$authors = $post->authors(', ', true);Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post tags
Return { Array } The post tags
$tags = $post->tags;Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post tags formated
| Name | Type | Description | Status | Default |
|---|---|---|---|---|
| $glue | { String } | The character used to glue together the tags | optional | ", " |
| $link | { Boolean } | If want a link around each tags or not | optional | true |
Return { String } The post tags formated
$tags = $post->tags(', ', true);Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post comments
| Name | Type | Description | Status | Default |
|---|---|---|---|---|
| $args | { Array } | The argument to pass to the get_comments wordpress function |
optional | [] |
Return { Array<WPS_Comment> } An array of WPS_Comment object
$comments = $posts->comments();Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post date formated
| Name | Type | Description | Status | Default |
|---|---|---|---|---|
| $format | { String } | The format wanted for the date | optional | null |
Return { String } The post data formated
$date = $post->date();Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get a meta for this post
Return { Mixed } The meta value
$viewed_count = $post->meta('post_viewed');
// 10Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Get the post viewed count
This need that the WPS::count_post_views() to be called inside your functions.php file
Return { Integer } The number of views for this post
$post->viewed_count;
// 10Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Check if the post is published or not
Return { Boolean } true if published, false if not
$post->is_published();
// trueAuthor : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Check if the post is pending or not
Return { Boolean } true if pending, false if not
$post->is_pending();
// falseAuthor : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Check if the post is in draft or not
Return { Boolean } true if draft, false if not
$post->is_draft();
// falseAuthor : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Check if the post is private or not
Return { Boolean } true if private, false if not
$post->is_private()
// falseAuthor : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Check if the post is sticky or not
Return { Boolean } true if sticky, false if not
$post->is_sticky();
// trueAuthor : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public
Check if the post is password protected or not
Return { Boolean } true if password protected, false if not
$post->is_password_protected();
// falseAuthor : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com
Public