0

Hello I want to change my taxonomies and posts permalink. I have taxonomies like that;

  • Audi
    • A1
      • 1.4 TFSI
      • 1.6 TDI
    • A3
      • 1.2
      • 1.4
      • 1.6
  • BMW
    • 1 series
      • 115d
      • 116d
    • 2 series
      • 220d

Question 1 ) How Can I change permalink for taxonomy as

  • site.com/brand/audi
  • site.com/brand/audi/a1
  • site.com/brand/audi/a1/14-tfsi
  • site.com/brand/audi/a1/16-tdi
  • site.com/brand/bmw
  • site.com/brand/bmw/1-series
  • site.com/brand/bmw/1-series/115d

Question 2 ) How Can I change permalink for posts

  • site.com/bmw/1-series/115d/post-title
  • site.com/audi/a1/16-tdi/post-title

This is Code What I use;

## Auto Post Type
function autoCats() {
## Brand - Model - Version
register_taxonomy(
'brand',
'auto',
array(
    'hierarchical'      => true,
    'label'             => 'Marka / Model / Versiyon',
    'query_var'         => true,
    'rewrite'           => array(
            'slug'          => 'marka',
            'with_front'    => false
    )
)
);
}
add_action( 'init', 'autoCats', 0 );

function autoRegister() {
    $labels = array(
        'name' => _x( 'Araç', 'catchthemes_custom_post','catchthemes' ),
        'singular_name' => _x( 'Araç', 'catchthemes_custom_post', 'catchthemes' ),
        'add_new' => _x( 'Araç Ekle', 'catchthemes_custom_post', 'catchthemes' ),
        'add_new_item' => _x( 'Yeni Bir Araç Ekle', 'catchthemes_custom_post', 'catchthemes' ),
        'edit_item' => _x( 'Aracı Düzenleyin', 'catchthemes_custom_post', 'catchthemes' ),
        'new_item' => _x( 'Yeni Araç', 'catchthemes_custom_post', 'catchthemes' ),
        'view_item' => _x( 'Aracı Önizleyin', 'catchthemes_custom_post', 'catchthemes' ),
        'search_items' => _x( 'Araç Ara', 'catchthemes_custom_post', 'catchthemes' ),
        'not_found' => _x( 'Henüz Araç Eklenmemiş', 'catchthemes_custom_post', 'catchthemes' ),
        'not_found_in_trash' => _x( 'Çöp Kutusunda Birşey Bulunamadı', 'catchthemes_custom_post', 'catchthemes' ),
        'parent_item_colon' => _x( 'Parent ThemePost:', 'catchthemes_custom_post', 'catchthemes' ),
        'menu_name' => _x( 'Araçlar', 'catchthemes_custom_post', 'catchthemes' ),
);

$args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'description' => 'Araç',
        'supports' => array( 'title', 'thumbnail', 'editor', 'comments', 'custom-fields' ),
        'taxonomies' => array('brand', 'post_tag', 'auto_cat'), // this is IMPORTANT
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'menu_icon' => get_stylesheet_directory_uri() . '/img/iconAuto.png',
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'query_var' => true,
        'can_export' => true,
        'hierarchical' => true,
        //'rewrite' => true <-- this is what you need!
        //'rewrite' => array('slug' => '%auto_cat%/%brand%','with_front' => false),
        'public' => true,
        'has_archive' => 'auto',
        'capability_type' => 'post'
);
register_post_type( 'auto', $args );
}
add_action( 'init', 'autoRegister', 20 );
  • Could you post the code you are using to register your taxonomy? – Jan Beck Sep 28 '14 at 22:00
  • I've just added – Burak Şahin Sep 28 '14 at 22:25
0

Go to the permalinks setting in the wordpress settings page and change the permalink structure to this.

 https://mysite.com/%category%/%postname%/

And now add this code in your .htaccess file to achieve that permalink structure.

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.