Switch language

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




_get_last_post_time [ WordPress Function ]

_get_last_post_time ( $timezone, $field )
Access:
  • private
Parameters:
  • (string) $timezone The location to get the time. Can be 'gmt', 'blog', or 'server'.
  • (string) $field Field to check. Can be 'date' or 'modified'.
Returns:
  • (string) The date.
Defined at:



Retrieve latest post date data based on timezone.

Source


<?php
function _get_last_post_time$timezone$field ) {
    global 
$wpdb;

    if ( !
in_array$field, array( 'date''modified' ) ) )
        return 
false;

    
$timezone strtolower$timezone );

    
$key "lastpost{$field}:$timezone";

    
$date wp_cache_get$key'timeinfo' );

    if ( !
$date ) {
        
$add_seconds_server date('Z');

        
$post_types get_post_types( array( 'public' => true ) );
        
array_walk$post_types, array( &$wpdb'escape_by_ref' ) );
        
$post_types "'" implode"', '"$post_types ) . "'";

        switch ( 
$timezone ) {
            case 
'gmt':
                
$date $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
                break;
            case 
'blog':
                
$date $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
                break;
            case 
'server':
                
$date $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
                break;
        }

        if ( 
$date )
            
wp_cache_set$key$date'timeinfo' );
    }

    return 
$date;
}
?>

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