Switch language

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




get_post [ WordPress Function ]

get_post ( $post, $output = OBJECT, $filter = 'raw' )
Parameters:
  • (int|object) $post Post ID or post object.
  • (string) $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
  • (string) $filter Optional, default is raw.
Uses:
  • $wpdb
Links:
Returns:
  • (mixed) Post data
Defined at:



Retrieves post data given a post ID or post object.

See {@link sanitize_post()} for optional $filter values. Also, the parameter $post, must be given as a variable, since it is passed by reference.

Source


<?php
function &get_post(&$post$output OBJECT$filter 'raw') {
    global 
$wpdb;
    
$null null;

    if ( empty(
$post) ) {
        if ( isset(
$GLOBALS['post']) )
            
$_post = & $GLOBALS['post'];
        else
            return 
$null;
    } elseif ( 
is_object($post) && empty($post->filter) ) {
        
_get_post_ancestors($post);
        
$_post sanitize_post($post'raw');
        
wp_cache_add($post->ID$_post'posts');
    } elseif ( 
is_object($post) && 'raw' == $post->filter ) {
        
$_post $post;
    } else {
        if ( 
is_object($post) )
            
$post_id $post->ID;
        else
            
$post_id $post;

        
$post_id = (int) $post_id;
        if ( ! 
$_post wp_cache_get($post_id'posts') ) {
            
$_post $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1"$post_id));
            if ( ! 
$_post )
                return 
$null;
            
_get_post_ancestors($_post);
            
$_post sanitize_post($_post'raw');
            
wp_cache_add($_post->ID$_post'posts');
        }
    }

    if (
$filter != 'raw')
        
$_post sanitize_post($_post$filter);

    if ( 
$output == OBJECT ) {
        return 
$_post;
    } elseif ( 
$output == ARRAY_A ) {
        
$__post get_object_vars($_post);
        return 
$__post;
    } elseif ( 
$output == ARRAY_N ) {
        
$__post array_values(get_object_vars($_post));
        return 
$__post;
    } else {
        return 
$_post;
    }
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



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