1

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

1 Answer 1

2

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.