Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Been all over looking for the best way to do this.

I want to get the ID of the latest post of a certain post_type.

How can I do this in the cheapest way possible (by cheapest I mean using the least queries, and no loops or post rewinding)?

Surely there is a quick method?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted
$latest_cpt = get_posts("post_type=yourcpt&numberposts=1");
echo $latest_cpt[0]->ID

The only cheaper way than above, I can think of, would be to write your own SQL query to just return the one post and only the column ID.

share|improve this answer
    
Yes, that's it! I've been skirting around it. Thanks @brady –  Niels Sep 7 '11 at 7:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.