-1

I am using the following code to list sub pages of a particular page.

How would I change ot to sort by alphabetical order?

<?php $args=array(
  'post_parent' => 15901,
  'post_type' => 'page',
  'orderby' => 'the_title',
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
        <ul>
<?php
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <li><h4><a href="<?php the_permalink() ?>">
            <?php $brand_name  = get_post_meta($post->ID, 'brand_name', true); ?><?php echo $brand_name; ?>
            </a></h4>
        </li>
   <?php endwhile; } ?>
    </ul>
<?php wp_reset_query();?>
4
  • 1
    It is in the docs, title, not the_title Commented Jul 4, 2016 at 12:30
  • Or perhaps OP is trying to order by brand name.
    – cjbj
    Commented Jul 4, 2016 at 12:41
  • wp_reset_query is for cleaning up after a query_posts call, you want to use wp_reset_postdata instead, and you need to call at the end of the if statement, not after it ( it cleans up after calls to $my_query->the_post() )
    – Tom J Nowell
    Commented Jul 4, 2016 at 12:48
  • Also don't hardcode your post IDs, use get_the_ID() instead
    – Tom J Nowell
    Commented Jul 4, 2016 at 12:49

1 Answer 1

1

Please change 'orderby' => 'the_title' to 'orderby' => 'title' then you will get the posts in alphabetical order.

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.