wpseek.com
A WordPress-centric search engine for devs and theme authors
get_post › WordPress Function
Since1.5.1
Deprecatedn/a
› get_post ( $post = null, $output = OBJECT, $filter = 'raw' )
Parameters: (3) |
|
Returns: |
|
Defined at: |
|
Codex: |
Retrieves post data given a post ID or post object.
See sanitize_post() for optional $filter values. Also, the parameter$post
, must be given as a variable, since it is passed by reference.Source
function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { if ( empty( $post ) && isset( $GLOBALS['post'] ) ) { $post = $GLOBALS['post']; } if ( $post instanceof WP_Post ) { $_post = $post; } elseif ( is_object( $post ) ) { if ( empty( $post->filter ) ) { $_post = sanitize_post( $post, 'raw' ); $_post = new WP_Post( $_post ); } elseif ( 'raw' === $post->filter ) { $_post = new WP_Post( $post ); } else { $_post = WP_Post::get_instance( $post->ID ); } } else { $_post = WP_Post::get_instance( $post ); } if ( ! $_post ) { return null; } $_post = $_post->filter( $filter ); if ( ARRAY_A === $output ) { return $_post->to_array(); } elseif ( ARRAY_N === $output ) { return array_values( $_post->to_array() ); } return $_post; }