Skip to content

Instantly share code, notes, and snippets.

@gbyat
Last active March 24, 2024 17:41
Show Gist options
  • Save gbyat/8708197 to your computer and use it in GitHub Desktop.
Save gbyat/8708197 to your computer and use it in GitHub Desktop.
get latest and first post in WordPress
/******************************************
* get latest post
* use in loop if ( is_latest() ) { stuff; }
******************************************/
function is_latest() {
global $post;
$loop = get_posts( 'numberposts=1' );
$latest = $loop[0]->ID;
return ( $post->ID == $latest ) ? true : false;
}
/******************************************
* get first post
* use in loop if ( is_first() ) { stuff; }
******************************************/
function is_first() {
global $post;
$loop = get_posts( 'numberposts=1&order=ASC' );
$first = $loop[0]->ID;
return ( $post->ID == $first ) ? true : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment