Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_latest_posts() {
- global $post_request_ajax;
- $load_time = $_GET['load_time'];
- $frontpage = $_GET['frontpage'];
- $num_posts = 10; // max amount of posts to load
- $number_of_new_posts = 0;
- $visible_posts = isset( $_GET['vp'] ) ? (array)$_GET['vp'] : array();
- query_posts( 'showposts=' . $num_posts . '&post_status=publish' );
- ob_start();
- while ( have_posts() ) : the_post();
- $current_user_id = get_the_author_meta( 'ID' );
- // Avoid showing the same post if it's already on the page
- if ( in_array( get_the_ID(), $visible_posts ) )
- continue;
- // Only show posts with post dates newer than current timestamp
- if ( get_gmt_from_date( get_the_time( 'Y-m-d H:i:s' ) ) <= $load_time )
- continue;
- $number_of_new_posts++;
- $post_request_ajax = true;
- p2_load_entry( false );
- endwhile;
- $posts_html = ob_get_clean();
- if ( $number_of_new_posts != 0 ) {
- nocache_headers();
- echo json_encode( array(
- 'numberofnewposts' => $number_of_new_posts,
- 'html' => $posts_html,
- 'lastposttime' => gmdate( 'Y-m-d H:i:s' )
- ) );
- } else {
- nocache_headers();
- header( 'HTTP/1.1 200 OK' );
- exit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement