RUSSEL86

Sort custom posts title alphabetically for qtranslate

Aug 4th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2. $my_query = new WP_Query( array('post_type'=>'page', 'orderby'=>'title', 'order'=>'ASC', 'posts_per_page'=>-1) );
  3. if ( $my_query ->have_posts() ):
  4. ?>
  5. <ul class="posts-list">
  6. <?php
  7. $found_posts = array();
  8. foreach ( $my_query->posts as $k=>$p ) {
  9. $found_posts[ apply_filters('the_title', $p->post_title) ] = $p;
  10. }
  11. ksort($found_posts);
  12. $i=0;
  13. foreach ($found_posts as $k=>$p) {
  14. $my_query->posts[$i++] = $p;
  15. }
  16. ?>
  17. <?php while ( $my_query->have_posts() ): $my_query->the_post(); ?>
  18. <li><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2></li>
  19. <?php endwhile; ?>
  20. </ul>
  21. <?php endif; wp_reset_postdata(); ?>
Advertisement
Add Comment
Please, Sign In to add comment