Advertisement
phpface

Untitled

Aug 28th, 2018
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. if( ! function_exists( 'videotube_prefilter_orderby' ) ){
  2.     function videotube_prefilter_orderby( $query ) {
  3.         if( isset( $_REQUEST['order_post'] ) && in_array( $_REQUEST['order_post'], array( 'title' , 'name', 'post_name' ) ) ){
  4.             if( $query->is_home() ||  $query->is_search || is_tax() || is_archive() && !is_admin() ){
  5.                 if( $query->is_main_query() ){
  6.                     $query->set( 'orderby', $_REQUEST['order_post'] );
  7.                     $query->set( 'order', 'ASC' );
  8.                 }
  9.             }
  10.         }
  11.     }
  12.     add_action('pre_get_posts', 'videotube_prefilter_orderby' );
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement