Advertisement
Guest User

part codes

a guest
Dec 8th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. // add region category to main queries
  2. add_action('pre_get_posts', 'tg_set_region');
  3. function tg_set_region( $query ) {
  4.     //--------debug-----------
  5. //if ( !is_admin() && $query->is_main_query())
  6.  //  print_r( $query );
  7. //-----------------------
  8.   if ( get_option('page_on_front') == $query->get('page_id')) return;
  9.   if ( !is_admin() && $query->is_main_query()) {
  10.     global $region;
  11.     $explode = explode('/', $_SERVER['REQUEST_URI']);
  12.     $cat = $query->get('category_name');
  13.     $region = $explode[1];  // $region = 'benelux'; //$explode[1];
  14.     if ( '' != $cat ) $cat .= '+' . $region;
  15.         else $cat = $region;
  16.     $query->set('category_name', $cat);
  17.   }
  18. }
  19.  
  20.  
  21. and
  22.  
  23.  
  24.  
  25. // Insert region into post links
  26. add_filter('post_link', 'tg_add_region', 999, 3 );
  27. function tg_add_region( $link, $post, $leavename) {
  28.    global $region;
  29.    $link = str_replace('.com/', ".com/$region/", $link );
  30.    return $link;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement