Advertisement
phpface

Untitled

Sep 20th, 2017
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. if( ! function_exists( 'videotube_child_reorder_videos_with_like' ) ){
  2.     /**
  3.      * Reoder videos based on liked
  4.      * @param $query
  5.      */
  6.     function videotube_child_reorder_videos_with_like( $query ) {
  7.        
  8.         $order = isset( $_REQUEST['order_post'] ) ? trim( $_REQUEST['order_post'] ) : null;
  9.        
  10.         if( $query->is_home() ||  $query->is_search || is_tax( 'video_tag' ) || is_tax( 'categories' ) || is_post_type_archive( 'video' ) && !is_admin() ){
  11.             if( $query->is_main_query() && ( $order == 'liked' || is_null( $order ) ) ){
  12.                 $query->set( 'meta_key','like_key' );
  13.                 $query->set( 'orderby', 'meta_value_num date' );
  14.             }
  15.         }
  16.        
  17.     }
  18.     add_action('pre_get_posts', 'videotube_child_reorder_videos_with_like', 100 );
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement