Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // add region category to main queries
- add_action('pre_get_posts', 'tg_set_region');
- function tg_set_region( $query ) {
- //--------debug-----------
- //if ( !is_admin() && $query->is_main_query())
- // print_r( $query );
- //-----------------------
- if ( get_option('page_on_front') == $query->get('page_id')) return;
- if ( !is_admin() && $query->is_main_query()) {
- global $region;
- $explode = explode('/', $_SERVER['REQUEST_URI']);
- $cat = $query->get('category_name');
- $region = $explode[1]; // $region = 'benelux'; //$explode[1];
- if ( '' != $cat ) $cat .= '+' . $region;
- else $cat = $region;
- $query->set('category_name', $cat);
- }
- }
- and
- // Insert region into post links
- add_filter('post_link', 'tg_add_region', 999, 3 );
- function tg_add_region( $link, $post, $leavename) {
- global $region;
- $link = str_replace('.com/', ".com/$region/", $link );
- return $link;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement