Reputation: 453
I've been stuck for hours in trying to order get_pages()
object from wordpress.
I need to order the pages by menu_order
(get_pages->menu_order
);
I've been trying several PHP functions but none worked in such purpose.
PHP
foreach(get_pages(pll_current_language()) as $page) {
// Somewhere here each page should go up/down in order to be DESC/ASC
$template = get_post_meta( $page->ID, '_wp_page_template', true );
include_once($template);
}
My question is, How can I order this object by one of its values, example:
I want to order get_pages() by get_pages()->menu_order
Any help will be appreciated.
Upvotes: 0
Views: 58
Reputation:
just use the $args
options array and set the sort_order
, sort_column
on whatever you need, check the docs https://codex.wordpress.org/Function_Reference/get_pages
$args = [
'sort_order' => 'asc',
'sort_column' => 'menu_order'
];
$pages = get_pages($args);
Upvotes: 3