Advertisement
pixedelic

pre_get_posts_change_order

Aug 27th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2.  
  3. /* It changes the order only for the main blog page */
  4. if ( ! function_exists( 't_n_order' ) ) :
  5. add_filter( 'pre_get_posts', 't_n_order' );
  6. function t_n_order( $query ) {
  7.     if($query->is_home)
  8.         $query->set( 'order' , 'asc' );
  9.     return $query;
  10. }
  11. endif;
  12.  
  13. /* It changes all over the site */
  14. if ( ! function_exists( 't_n_order' ) ) :
  15. add_filter( 'pre_get_posts', 't_n_order' );
  16. function t_n_order( $query ) {
  17.     $query->set( 'order' , 'asc' );
  18.     return $query;
  19. }
  20. endif;
  21. /* It changes the order for the main blog page, categories, tag pages and the other post archives */
  22. if ( ! function_exists( 't_n_order' ) ) :
  23. add_filter( 'pre_get_posts', 't_n_order' );
  24. function t_n_order( $query ) {
  25.     if($query->is_home || $query->is_archive)
  26.         $query->set( 'order' , 'asc' );
  27.     return $query;
  28. }
  29. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement