wp_get_single_post [ WordPress Function ]
wp_get_single_post ( $postid = 0, $mode = OBJECT )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Similar Functions: get_next_post, wp_get_recent_posts, wp_insert_post, wp_delete_post, wp_remote_post
Retrieve a single post, based on post ID.
Has categories in 'post_category' property or key. Has tags in 'tags_input' property or key.
Source
<?php
function wp_get_single_post($postid = 0, $mode = OBJECT) {
$postid = (int) $postid;
$post = get_post($postid, $mode);
if (
( OBJECT == $mode && empty( $post->ID ) ) ||
( OBJECT != $mode && empty( $post['ID'] ) )
)
return ( OBJECT == $mode ? null : array() );
// Set categories and tags
if ( $mode == OBJECT ) {
$post->post_category = array();
if ( is_object_in_taxonomy($post->post_type, 'category') )
$post->post_category = wp_get_post_categories($postid);
$post->tags_input = array();
if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
$post->tags_input = wp_get_post_tags($postid, array('fields' => 'names'));
} else {
$post['post_category'] = array();
if ( is_object_in_taxonomy($post['post_type'], 'category') )
$post['post_category'] = wp_get_post_categories($postid);
$post['tags_input'] = array();
if ( is_object_in_taxonomy($post['post_type'], 'post_tag') )
$post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names'));
}
return $post;
}
?>
Examples [ wp-snippets.com ]
Top Google Search Results
- Function Reference/wp get single post « WordPress Codex
Description. Retrieve a single post, based on post ID. Usage. <?php wp_get_single_post( $postid, $mode ) ?> Parameters. $postid: (integer) (optional ) Post ID.
codex.wordpress.org - #13904 (wp_get_single_post and wp_update_post assume post ...
wp_update_post and wp_get_single_post assume both that the post object they try to retrieve exists and that it has certain properties. Theses assumptions do ...
core.trac.wordpress.org - wp_get_single_post (WordPress Function) - WPSeek.com
WordPress lookup for wp_get_single_post, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - 関数リファレンス/wp get single post - WordPress Codex 日本語版
2010年5月1日 ... <?php wp_get_single_post( $postid, $mode ) ?> ... ソースファイル. wp_get_single_post() は wp-includes/post.php に含まれています。
wpdocs.sourceforge.jp