fauzanjeg

Search Post By Tag

Aug 2nd, 2021 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. /* Search Post By Tag */
  2. function add_tag_live_search( $statement ) {
  3.     $new_statement = array(
  4.         'tax_query' => array(
  5.             'relation' => 'OR',
  6.             array(
  7.                 'taxonomy' => 'name',
  8.                 'field'    => 'slug',
  9.                 'terms'    => $statement['s'],
  10.             ),
  11.             array(
  12.                 'taxonomy' => 'post_tag',
  13.                 'field'    => 'slug',
  14.                 'terms'    => str_replace( ' ', '-', $statement['s'] ),
  15.             ),
  16.             array(
  17.                 'taxonomy' => 'post_tag',
  18.                 'field'    => 'slug',
  19.                 'terms'    => str_replace( ' ', '+', $statement['s'] ),
  20.             ),
  21.         ),
  22.     );
  23.     unset($statement['s']);
  24.  
  25.     return array_merge( $statement, $new_statement );
  26. }
  27. add_filter( 'jnews_live_search_args', 'add_tag_live_search' );
Add Comment
Please, Sign In to add comment