I've trying to get the latest post ID in WordPress, but the two different methods I am using are returning different results.
FYI if I look in PHPmyAdmin I can see the latest post ID is 3000.
If I do this...
$args = array(
'post_type' => 'any'
);
$the_ID = get_posts($args);
$latest_ID = $the_ID[0]->ID;
echo $latest_ID;
...it returns 2999 instead of 3000. This is very odd.
But if I specify some post types in an array like this...
$args = array(
'post_type' => array('post', 'page', 'attachment')
);
$the_ID = get_posts($args);
$latest_ID = $the_ID[0]->ID;
echo $latest_ID;
...it returns 3000 which is the correct ID but also not very maintainable.
My understanding is that 'post_type' => 'any' should include all post types, and obviously I don't want to use the 2nd method because I'd have to update the array manually every time there is a new post type.
Is there a way around this? Or perhaps a better way of getting the latest post ID?