[wp-hackers] Method to retrieve all posts/pages from a blog

Volkmar Seifert vs at nifelheim.info
Tue Apr 8 22:17:26 GMT 2008


> Did you try:
> $allposts = get_posts(array(numberposts' => 0, 'post_type' => ''));
>
> Looks like it should work.
>

Not until your eMail, thanks for pointing that out to me.

It did work, though while looking at the resulting array, I noticed that
this would mean a overhead of function-calls and most likely
database-accesses that won't really make up for the alleged advantage of
abstraction.
Especially for the case of sitemaps, one does not require the whole post,
only selected information (reduction of memory consumption), and not only
from the posts-table, but from the terms-table (for the categories) and
the user-table (for the names of the authors). A single sql-statement can
catch all that, whereas by using get_posts() would provide me with a
complete post without the category- and usernames. I would have to fetch
them manually, and that means at least two other sql-statements and
several function-calls.

Since this requirement is a bit special, I think it is better use direct
access through the $wpdb-object, with an appropriately crafted
sql-statement, and doing everything manually. It seems the more efficient
way for now.

Anyway, thanks for your help.

- Volkmar

-- 
http://blog.nifelheim.info/tech


More information about the wp-hackers mailing list