Wallogit.com
2017 © Pedro Peláez
Missing functionalities from model objects of WordPress.
Missing functionalities from model objects of WordPress., (*1)
Extended wrapper of native post object of WordPress, WP_Post., (*2)
$post = new WPModel\Post($post_id); // same properties of WP_Post are accessible echo $post->post_date; echo $post->post_title; echo $post->post_mime_type;
Get permalink of the post., (*3)
Returns: string, (*4)
$post = new WPModel\Post($post_id); echo $post->permalink;
Get child posts of the post., (*5)
Returns: array, (*6)
$post = new WPModel\Post($post_id); $children = $post->children(array( 'id' => array(10, 11, 12) )); $attachments = $post->children(array( 'post_type' => 'attachment' )); $images = $post->children(array( 'post_mime_type' => 'image' ));
Get terms attached to the post., (*7)
'category'
Returns: array, (*8)
$post = new WPModel\Post($post_id); $custom_terms = $post->terms(array( 'taxonomy' => 'custom_taxonomy' ));
PostMeta object of the post., (*9)
Retusns: WPModel\PostMeta, (*10)
$post = new WPModel\Post($post_id); // get meta value echo $post->meta->custom_field; // set meta value $post->meta->custom_field = 'hello';
Get WPModel\Image object if the post is an image attachment., (*11)
'full', 'large', 'medium', 'thumbnail'). Default value: 'full'
Returns: WPModel\Image, (*12)
$post = new WPModel\Post($post_id); $thumbnail = $post->image(array( 'size' => 'thumbnail' )); echo $thumbnail->url; echo $thumbnail->path; echo $thumbnail->width; echo $thumbnail->height;
Get images array if the post is an image attachment., (*13)
Returns: array, (*14)
$post = new WPModel\Post($post_id); $images = $post->images; // get WPModel\Image object $images['full']; $images['large']; $images['medium']; $images['thumbnail'];
Retrieve posts grouped by same terms., (*15)
'category'
WP_Query that is internally called.array('WPModel\Post', 'create')
Returns: array, (*16)
$post = new WPModel\Post($post_id);
$related_posts = $post->group(array(
'taxonomy' => 'custom_taxonomy',
'options' => array('posts_per_page' => 5),
'map' => function($post) {
return CustomPostClass($post);
},
));
Retrieve a prev/next WP_Post object. Returns null if it doesn’t exist., (*17)
$this->post_type
prev or next
Returns: WP_Post, (*18)
$post = new WPModel\Post($post_id); $prev_post = $post->neighbor(array( 'post_type' => ['post', 'custom_post_type'], 'direction' => 'prev', ));
Return true if the post exists., (*19)
Returns: boolean, (*20)
$post = new WPModel\Post(0); $post->exists; // => false
Return true if the value is a child of the post., (*21)
Returns: boolean, (*22)
$post = new WPModel\Post($post_id); $post->hasChild($child_post);
Return true if the value matches mime type of the post. For example, 'image/jpeg', 'image' and 'jpeg' match 'image/jpeg'., (*23)
Retusns: boolean, (*24)
$post = new WPModel\Post($post_id);
$post->matchMimeType('image/jpeg');
See ->meta of WPModel\Post., (*25)
Extended wrapper of native term object of WordPress. See return values of wp_get_post_terms., (*26)
// create by constructor $term = new WPModel\Term($term_id, 'custom_taxonomy'); // get from WPModel\Post $post = new WPModel\Post($post_id); $terms = $post->terms(array( 'taxonomy' => 'custom_taxonomy' ));
Get child terms of the term., (*27)
$args of get_terms.$child_terms = $term->children(array( 'orderby' => 'count', 'hide_empty' => false ));
See ->image of WPModel\Post., (*28)
Extended wrapper of native user object of WordPress, WP_User., (*29)
// current user $user = new WPModel\User(); // specify user id $user = new WPModel\User($user_id); // same properties of WP_User are accessible echo $user->user_email; echo $user->user_login; echo $user->first_name;
UserMeta object of the user., (*30)
Returns: WPModel\UserMeta, (*31)
$user = new WPModel\User(); // get meta value echo $user->meta->rich_editing; // set meta value $user->meta->rich_editing = 'false';
Return true if the user exists., (*32)
Returns: boolean, (*33)
$post = new WPModel\User(); $post->exists; // => true
See ->meta of WPModel\User., (*34)