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.

I have this function which gives me IDs and titles of all child pages of a given parent ID.

function getPageChildren($page_id) {

  $my_wp_query = new WP_Query();
  $all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));

  $page_children = get_page_children($page_id, $all_wp_pages);

  foreach ($page_children as $p) {    
    $tmp['id'] = $p->ID;
    $tmp['title'] = $p->post_title;    
    $pages[] = $tmp;
  }

  return $pages;    
}

I want some way of ordering them in the backend, which I'd presume is done in the page attributes box of the edit page in the Order field?

I have amended my the second statement in the above with the following:

$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'sort_order' => 'ASC', 'sort_column' => 'menu_order'));

hoping this would tell the function to talke into account the order I specify, but this doesn't seem to work.

Can anyone tell me how I am supposed to order the results of my function from the backend please?

Thanks

share|improve this question

1 Answer 1

up vote 1 down vote accepted

sort_column is not a valid parameter for WP_Query. You want orderby. sort_order is also not a valid parameter. It should just be order.

$all_wp_pages = $my_wp_query->query(
    array(
        'post_type' => 'page', 
        'order' => 'ASC', 
        'orderby' => 'menu_order'
    )
);

The Codex is your friend.

share|improve this answer
    
thanks.......... –  Larry B Jan 13 '13 at 16:37

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.