Advertisement
marstheme

Untitled

May 7th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. if( ! function_exists( 'videotube_child_reorder_videos' ) ){
  2.  
  3.     /**
  4.      * Reoder videos based on viewed
  5.      * @param $query
  6.      */
  7.  
  8.     function videotube_child_reorder_videos( $query ) {
  9.  
  10.         $order = isset( $_REQUEST['order_post'] ) ? trim( $_REQUEST['order_post'] ) : null;
  11.  
  12.         if( $query->is_home() ||  $query->is_search || is_tax() || is_archive() && !is_admin() ){
  13.                
  14.             if( $query->is_main_query() ){
  15.                 if( empty( $order ) || $order == 'viewed' ){
  16.                     $query->set( 'meta_key','count_viewed' );
  17.                     $query->set( 'orderby', 'meta_value_num' );
  18.                 }
  19.             }
  20.         }
  21.  
  22.     }
  23.  
  24.     add_action('pre_get_posts', 'videotube_child_reorder_videos');
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement