Advertisement
Guest User

wp > Search & Filter > empty result redirect

a guest
Feb 8th, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     /* this is the very beginning of the index.php */
  3.  
  4.     /*
  5.     * redirect when search & find is empty:
  6.     * problem: under circumstances (querying by many parameters) there is an empty result and instead of the archive.php the index.php opens  
  7.     * hacky solution: check for the parameter 'post_types' in the url on index.php and if found, redirect to the specific archive page
  8.     * note: change the post_types var's to yours, change the url slug fitting your slugs
  9.     */
  10.     if(isset($_GET['post_types'])) {
  11.         $var = $_GET['post_types'];
  12.         if($var == 'publication'){
  13.             wp_safe_redirect( ''.get_home_url().'/publication' ); exit;
  14.         }else if ($var == 'project'){
  15.             wp_safe_redirect( ''.get_home_url().'/projects' ); exit;
  16.         }
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement