WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So hard to find this info...

I'd like to know a way to find out if there are pages. Something like:

if (has_pages()) { /* do something */ }

I can't find a reference to any similar function... how might one go about finding out if there are pages. In case yr wondering I'd like to only show a pages menu if there are pages.

share|improve this question
up vote 1 down vote accepted

You could also use wp_list_pages() (Codex ref):

$has_pages = wp_list_pages( array( 'echo' => false ) );

if ( $has_pages ) {
    // There are pages; do something
share|improve this answer

You might try using wp_count_posts, which will return an object with post statuses as properties. For example:

$count_pages = wp_count_posts( 'page' );
if ( $count_pages->publish > 0) {
   /* do something */

If you want to count all of the various statuses together, I imagine you'd just have to do a little addition before doing the compare.

share|improve this answer
That's some great lateral thinking there. Does it seem strange to you there is not a function already handling this scenario? – Niels Jul 18 '11 at 15:49
I personally think wp_count_posts is pretty much right on, though maybe it would be nice if it came with an "all" property :) – helenhousandi Jul 18 '11 at 18:56

Your Answer


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.