Switch language

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




wp_get_post_autosave [ WordPress Function ]

wp_get_post_autosave ( $post_id )
Parameters:
  • (int) $post_id The post ID.
Returns:
  • (object|bool) The autosaved data or false on failure or when no autosave exists.
Defined at:



Retrieve the autosaved data of the specified post.

Returns a post object containing the information that was autosaved for the specified post.

Source


<?php
function wp_get_post_autosave$post_id ) {

    if ( !
$post get_post$post_id ) )
        return 
false;

    
$q = array(
        
'name' => "{$post->ID}-autosave",
        
'post_parent' => $post->ID,
        
'post_type' => 'revision',
        
'post_status' => 'inherit'
    
);

    
// Use WP_Query so that the result gets cached
    
$autosave_query = new WP_Query;

    
add_action'parse_query''_wp_get_post_autosave_hack' );
    
$autosave $autosave_query->query$q );
    
remove_action'parse_query''_wp_get_post_autosave_hack' );

    if ( 
$autosave && is_array($autosave) && is_object($autosave[0]) )
        return 
$autosave[0];

    return 
false;
}
?>

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