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.

I run a website for a company with a careers section, with each vacancy posted as a custom post type. When vacancies are available, ie a post type of "vacancy" is published, we want to display a ribbon in the top corner, directing people to the careers page.

To check for published posts obviously I could get_posts for that post type, but that seems a bit inefficient as I'll be battering the database on every page load to check. Is there any more DB efficient way of doing this, kind of like a have_posts( 'post_type=vacancy' ) ?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I wouldn't worry about doing a second query (e.g. using get_posts()). If you want to check if a post type has any published posts - you're going to have to query the database. But reading a database is really quick - any noticable delay in your page load is more likely to come from extra HTTP requests (images, javascript, css etc).

In any case, if you are worried about speed, you presumably have some sort cache plug-in enabled, in which case, most of your visitors won't notice a difference. In fact, you entire page will only be generated if the cache has expired.

share|improve this answer
    
Cool, thanks for that. I hadn't noticed any particular slowdown, I'm just always keen to keep it talking to the database as little as possible. And yea we are running a caching plugin. –  artparks May 9 '12 at 11:39
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.