[wp-hackers] Getting every page ID, URL, and Title on site

Philip Walton philip at philipwalton.com
Thu Apr 7 18:35:51 UTC 2011


Robert, I have a plugin that does a similar thing to what you're asking:
PW_Archives <http://wordpress.org/extend/plugins/pw-archives/> (to toot my
own horn). You can probably look at the source, specifically the queries I'm
doing, and customize them for your purposes.

I had the same problem you're having because in order to get the permalink
of a post via a WordPress function, you have to download its content from
the database as well, which seems like an incredible waste to me since some
of my sites have 1000+ posts with tons of content.

My solution was kind of hackish, but basically I'm doing a custom query for
all the posts and creating a fake post object (excluding content and other
unnecessary stuff), so get_permalink doesn't run an additional query. The
only problem with this is if the user has some crazy permalink structure
that requires this extra post info, it'll break.

I did some testing on my site and it reduced page load from like 3 seconds
to less than a second.

Hope that helps.



On Thu, Apr 7, 2011 at 11:25 AM, Robert Lusby <nanogwp at gmail.com> wrote:

> Any ideas on the cleanest way to list every page (inc pages, posts, and
> custom post types) in a site?
>
> I only require ID, Title and Permalink(URL) for each page.
>
> Seems so simple, but running a loop seems so excessive as I don't require
> the page content at all ... and get_pages only works on pages (not custom
> post types) (plus also returns content).
>
> Any suggestions for the least intensive way to simply get these three
> items?
>
> Thanks,
> Rob
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Philip Walton


More information about the wp-hackers mailing list