I have a custom loop working nicely - but i want the loop to list the results in alphabetical order based on post_title - can someone help me update the code below to get it to work please // thanks
<?php
$ids = array();
$pages = get_pages("child_of=".$post->ID);
if ($pages) {
foreach ($pages as $page) {
$ids[] = $page->ID;
}
}
$paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
$args = array(
"paged" => $paged,
"post__in" => $ids,
"posts_per_page" => 50000,
"post_type" => "page"
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
?>
CodePudding user response:
Add 'orderby' => 'title',
to your query args like below:
<?php
$ids = array();
$pages = get_pages("child_of=".$post->ID);
if ($pages) {
foreach ($pages as $page) {
$ids[] = $page->ID;
}
}
$paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
$args = array(
"paged" => $paged,
"post__in" => $ids,
"posts_per_page" => 50000,
"post_type" => "page",
"orderby" => "title", // ADD THIS
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
?>