get_post [ WordPress Function ]
get_post ( $post, $output = OBJECT, $filter = 'raw' )
| Parameters: |
|
| Uses: |
|
| Links: | |
| Returns: |
|
| 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ý
- get_post - WordPress Codex
Description. Takes a post ID and returns the database record for that post. You can specify, by means of the $output parameter, how you would like the results ...
codex.wordpress.org - get_posts() - WordPress Codex
get_posts() makes use of the WP_Query class to fetch posts. See the parameters section of the WP_Query documentation for a list of parameters that this ...
codex.wordpress.org - get_post() | Code Garage Blog
Sep 15, 2011 ... See how in the example above, I set $id to 41, an then used $id as the argument to get_post(), instead of just saying get_post(41)?
codegarage.com - Getting only a specific post type with get_post? - WordPress
Mar 25, 2011 ... I'm using the following function to get some posts based on their vote (Vote it Up plugin): function top_voted($number){ $a = SortVotes(); echo ...
wordpress.stackexchange.com
Kullanýcý Tartýþmalarý [ wordpress.org ]
- Digital Raindrops on "displaying separate posts based on sequential order"
- harberg on "displaying separate posts based on sequential order"
- Digital Raindrops on "displaying separate posts based on sequential order"
- harberg on "displaying separate posts based on sequential order"
- stinkykiller on "Getting the post from start to"
- stinkykiller on "Getting the post from start to"
- alchymyth on "Getting the post from start to"
- stinkykiller on "Getting the post from start to"
- bibekpokharel on "Theme Development"
- justingreerbbi on "Theme Development"