Advertisement
Guest User

Untitled

a guest
May 23rd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. if( ! function_exists( 'videotube_pre_query_search_result' ) ){
  2.     /**
  3.      * Filter the query of search result
  4.      * @param $query
  5.      */
  6.     function videotube_pre_query_search_result( $query ) {
  7.         if( $query->is_search() && $query->is_main_query() ){
  8.             $query->set( 'tax_query',
  9.                 array(
  10.                     array(
  11.                         'taxonomy' => 'categories',
  12.                         'field' => 'id',
  13.                         'terms' => array( 243 ), // an array of video category, e.g: array( 1,2,3,4 )
  14.                         'operator' => 'IN'
  15.                     )
  16.                 )
  17.             );
  18.         }
  19.     }
  20.     add_action( 'pre_get_posts', 'videotube_pre_query_search_result', 10, 1 );
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement