Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'init', 'models_post_type' );
- function models_post_type() {
- register_post_type( 'models',
- array(
- 'labels' => array(
- 'name' => __( 'Models' ),
- 'singular_name' => __( 'Models' ),
- ),
- 'public' => true,
- 'has_archive' => 'model_category',
- 'menu_icon' => 'dashicons-id',
- 'rewrite' => array('slug' => 'categories/%model_category%','with_front' => false),
- 'supports' => array('title','editor','thumbnail','comments'),
- /* "cptp_permalink_structure" => "/categories/%model_category%/%postname%"*/
- )
- );
- }
- add_action( 'init', 'model_taxonomies', 0 );
- function model_taxonomies(){
- register_taxonomy(
- 'model_category',
- 'models',
- array(
- 'hierarchical' => true,
- 'label' => __('Model category'),
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'categories',
- 'with_front' => true,
- 'hierarchical' => false
- ),
- )
- );
- }
- add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
- function wpa_show_permalinks( $post_link, $post ){
- $list_posts = array(
- 'categories' => 'model_category',
- );
- foreach ($list_posts as $cpt => $tax){
- if ( is_object( $post ) && $post->post_type == $cpt ){
- $terms = wp_get_object_terms( $post->ID, $tax );
- $term_slug = $terms ? $terms[0]->slug : 'no-cat';
- return str_replace( '%'.$tax.'%' ,$term_slug, $post_link );
- }
- }
- return $post_link;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement