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.

Does a method exist that can return a simple array of the pages in the site that are published? I only want the name and the slug returned, not the full content or other default values.

I've tried WP_query(), get_posts(), get_pages() and query_posts() but they all return the post/page content. I'm only looking to get the post name and slug returned.

If there's no lighter method, I can use one of these. Just want to make sure.

Any help, much appreciated.

share|improve this question
    
I don't think there is, the only way to do that I think would be a custom query using the WPDB object. codex.wordpress.org/Function_Reference/wpdb_Class –  Cristian Apr 21 '11 at 18:37
    
Thanks. I wonder which of all of the above is the least resource intensive? I only need to grab the post_name and slug for about 5-6 pages so that I can add them to a custom menu on the fly. –  Scott B Apr 21 '11 at 18:54
    
how are you selecting these few pages? whats the query args? I'm asking because i know there is no way other the a custom sql query which is not that hard to do. –  Bainternet Apr 21 '11 at 19:07
    
@Bainternet: currently I'm just using $thePages = get_pages('post_type=page&post_status=publish&parent=0'); –  Scott B Apr 21 '11 at 19:22

1 Answer 1

up vote 1 down vote accepted

Like a commented the only way to do it is with a custom sql query so:

global $wpdb;
$mypages = $wpdb->get_results( "SELECT post_title, post_name FROM $wpdb->posts
 WHERE post_type = 'page' 
 AND post_status = 'publish' 
 AND parent = '0'");

if (count($mypages) > 0){
    foreach ($mypages as $page){
        //do you stuff
        //$page['post_title'] for title
        //$page['post_name'] for slug
    }
}
share|improve this answer
    
Thanks Bainternet. I'm assuming this is much lighter than my get_pages call. –  Scott B Apr 21 '11 at 19:49

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.