Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( ! function_exists( 'videotube_child_reorder_videos' ) ){
- /**
- * Reoder videos based on viewed
- * @param $query
- */
- function videotube_child_reorder_videos( $query ) {
- $order = isset( $_REQUEST['order_post'] ) ? trim( $_REQUEST['order_post'] ) : null;
- if( $query->is_home() || $query->is_search || is_tax() || is_archive() && !is_admin() ){
- if( $query->is_main_query() ){
- if( empty( $order ) || $order == 'viewed' ){
- $query->set( 'meta_key','count_viewed' );
- $query->set( 'orderby', 'meta_value_num' );
- }
- }
- }
- }
- add_action('pre_get_posts', 'videotube_child_reorder_videos');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement