Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_get_single_post [ WordPress Function ]

wp_get_single_post ( $postid = 0, $mode = OBJECT )
Parameters:
  • (int) $postid Post ID.
  • (string) $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A.
Returns:
  • (object|array) Post object or array holding post contents and information
Defined at:



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

More ...

User discussions [ wordpress.org ]

0 User Note(s)

None yet. Be the first!

Add New ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics