permalink Create with custom post types 404

Please flow codex:


// register the new post type
    register_post_type( 'vehicles_listing',
        array( 'labels' => array(
            'name' => __( 'Vehicles' ),
            'singular_name' => __( 'Vehicle' ),
            'add_new' => __( 'Add New' ),
            'add_new_item' => __( 'Create New Vehicle' ),
            'edit' => __( 'Edit' ),
            'edit_item' => __( 'Edit Vehicle' ),
            'new_item' => __( 'New Vehicle' ),
            'view' => __( 'View Vehicles' ),
            'view_item' => __( 'View Vehicles' ),
            'search_items' => __( 'Search Vehicles' ),
            'not_found' => __( 'No vehicles found' ),
            'not_found_in_trash' => __( 'No vehicles found in trash' ),





            'parent' => __( 'Parent vehicle' ),
            ),
            'description' => __( 'This is where you can create new vehicles on your site.' ),
            'public' => true,
            'show_ui' => true,
            'capability_type' => 'post',
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'menu_position' => 2,
            'menu_icon' => get_stylesheet_directory_uri() . '/images/tag_orange.png',
            'hierarchical' => true,
          '_builtin' => false, // It's a custom post type, not built in!
            'rewrite' => array( 'slug' => 'vehicles/%vehicle_cat%', 'with_front' => true ),
            'query_var' => true,
            'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields' ),
            )
);



//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_vehicle_taxonomies', 0 );
add_action('admin_init', 'flush_rewrite_rules');

//create two taxonomies, genres and writers for the post type "book"
function create_vehicle_taxonomies() 
{
  // Add new taxonomy, make it hierarchical (like categories)
  $labels = array(
    'name' => _x( 'Vehicle Categories', 'taxonomy general name' ),
    'singular_name' => _x( 'Vehicle Category', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Vehicle Category' ),
    'all_items' => __( 'All Vehicle Categories' ),
    'parent_item' => __( 'Parent Vehicle Category' ),
    'parent_item_colon' => __( 'Parent Vehicle Category:' ),
    'edit_item' => __( 'Edit Vehicle Category' ), 
    'update_item' => __( 'Update Vehicle Category' ),
    'add_new_item' => __( 'Add New Vehicle Category' ),
    'new_item_name' => __( 'New Vehicle Category Name' ),
    'menu_name' => __( 'Vehicle Categories' ),
  );    

  register_taxonomy('vehicle_cat',array('vehicles_listing'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    //'rewrite' => true,
    'rewrite' => array( 'slug' => 'vehicles', 'with_front' => true, 'hierarchical' => true ),
  )); 
}

add_action('vehicle_cat_add_form', 'qtrans_modifyTermFormFor');
add_action('vehicle_cat_edit_form', 'qtrans_modifyTermFormFor');

add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
function mmp_rewrite_rules($rules) {
    $newRules  = array();
    $newRules['/(.+)/(.+)/?$'] = 'index.php?custom_post_type_name=$matches[3]';
    $newRules['/(.+)/?$'] = 'index.php?custom_taxonomy=$matches[1]';
    return array_merge($newRules, $rules);
}

function filter_post_type_link($link, $post)
{
    if ($post->post_type != 'vehicles_listing')
        return $link;

    if ($cats = get_the_terms($post->ID, 'vehicle_cat'))
    {
        $link = str_replace('%vehicle_cat%', get_taxonomy_parents(array_pop($cats)->term_id, 'vehicle_cat', false, '/', true), $link); // see custom function defined below
    }
    return preg_replace('#/+#', '/', $link);
}
add_filter('post_type_link', 'filter_post_type_link', 10, 2);


// my own function to do what get_category_parents does for other taxonomies
function get_taxonomy_parents($id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array()) {    
    $chain = '';   
    $parent = &get_term($id, $taxonomy);

    if (is_wp_error($parent)) {
        return $parent;
    }

    if ($nicename)    
        $name = $parent -> slug;        
    else    
        $name = $parent -> name;

    if ($parent -> parent && ($parent -> parent != $parent -> term_id) && !in_array($parent -> parent, $visited)) {    
        $visited[] = $parent -> parent;    
        $chain .= get_taxonomy_parents($parent -> parent, $taxonomy, $link, $separator, $nicename, $visited);

    }

    if ($link) {
        // nothing, can't get this working :(
    } else    
        $chain .= $name. $separator; 
    return $chain;   
}

Comments

Popular posts from this blog

Text Smooth Scrolling Marquee use jQuery