// Add our own URL strucutre and rewrite rules
function my_add_rewrite_rules_turs() {
add_rewrite_tag('%turs%', '([^/]+)');
add_permastruct('turs', '/countries/%countries%/turs/%turs%', false);
add_rewrite_rule('^countries/([^/]+)/turs/([^/]+)/?','index.php?countries=$matches[1]&turs=$matches[2]','top');
}
add_action( 'init', 'my_add_rewrite_rules_turs' );
// Set permalink for Lessons
function my_permalinks_turs($permalink, $post, $leavename) {
$post_id = $post->ID;
if($post->post_type != 'turs' || empty($permalink))
return $permalink;
$parent = rwmb_get_value( 'countries' , $post_id );
$parent_post = get_post( $parent );
$permalink = str_replace('%countries%', $parent_post->post_name, $permalink);
return $permalink;
}
add_filter('post_type_link', 'my_permalinks_turs', 10, 3);
add_filter( 'template_include', 'include_post_type_second' );
function include_post_type_second( $template ) {
if ( (in_array('second', explode('/', $_SERVER['REQUEST_URI']))) ) {
if ( $new_template = locate_template( array( 'single-post_type-second.php' ) ) )
$template = $new_template ;
}
return $template;
}