Getting all pages in WordPress

      No Comments on Getting all pages in WordPress

WordPress provides elegant wp_query class to query and manipulate post. You can use query_posts to query the posts in your blog.  If used with The_Loop and other global variables, it is very powerful function.

Sometimes, instead of posts, you need to query all the pages of your website. WordPress use same table to store posts and pages. It distinguishes posts from page using pagetype attribute. Therefore, if you pass pagetype=page in the query_posts, what you will get is all the pages

[sourcecode language=”php”]

In the above query, I am getting all the pages, ordered ascending by their IDs

Leave a Reply

Your email address will not be published. Required fields are marked *