Advertisement
michaellevelup

Custom query sort for blog archive page

Jun 7th, 2022
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. //function to modify default WordPress query
  2. function king_custom_query( $query ) {
  3.    
  4.     // Make sure we only modify the main query
  5.     if( $query->is_main_query() && ! is_admin() && $query->is_archive() ) {
  6.    
  7.         // Set parameters to modify the query
  8.         $query->set( 'orderby', 'title' );
  9.         $query->set( 'order', 'ASC' );
  10.         $query->set( 'suppress_filters', 'true' );
  11.     }
  12. }
  13.    
  14. // Hook our custom query function to the pre_get_posts
  15. add_action( 'pre_get_posts', 'king_custom_query' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement