Switch language

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




get_post_field [ WordPress Function ]

get_post_field ( $field, $post, $context = 'display' )
Parameters:
  • (string) $field Post field name
  • (id) $post Post ID
  • (string) $context Optional. How to filter the field. Default is display.
Uses:
Returns:
  • (WP_Error|string) Value in post field or WP_Error on failure
Defined at:



Retrieve data from a post field based on Post ID.

Examples of the post field will be, 'post_type', 'post_status', 'post_content', etc and based off of the post object property or key names.

The context values are based off of the taxonomy filter functions and supported values are found within those functions.

Source


<?php
function get_post_field$field$post$context 'display' ) {
    
$post = (int) $post;
    
$post get_post$post );

    if ( 
is_wp_error($post) )
        return 
$post;

    if ( !
is_object($post) )
        return 
'';

    if ( !isset(
$post->$field) )
        return 
'';

    return 
sanitize_post_field($field$post->$field$post->ID$context);
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



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