Set order of returned items in the WP_Query() class/function

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?

Read More

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

Related posts

Leave a Reply

1 comment