Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('init', 'custom_init');
- add_filter('post_type_link', 'english_permalink', 1, 3);
- function custom_init(){
- register_post_type('english-posts',
- array('label' => 'English',
- 'query_var' => true,
- 'rewrite' => false
- )
- );
- register_taxonomy('english-categories',
- 'english-posts',
- array('query_var' => true,
- 'rewrite' => true
- )
- );
- global $wp_rewrite;
- $english_structure = '/%english-categories%/%english-posts%';
- $wp_rewrite->add_rewrite_tag("%english-posts%", '([^/]+)', "english-posts=");
- $wp_rewrite->add_permastruct('english-posts', $english_structure, false);
- }
- function english_permalink($permalink, $post_id, $leavename){
- $post = get_post($post_id);
- $rewritecode = array(
- '%english-categories%',
- $leavename? '' : '%postname%',
- $leavename? '' : '%pagename%',
- );
- if('' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft'))){
- if (strpos($permalink, '%english-categories%') !== FALSE){
- $terms = wp_get_object_terms($post->ID, 'english-categories');
- if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $english_categories = $terms[0]->slug;
- else $english_categories = 'unassigned';
- }
- $rewritereplace = array(
- $english_categories,
- $post->post_name,
- $post->post_name,
- );
- $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
- }
- else{
- }
- return $permalink;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement