• Hi-
    Let’s say I have a custom post type called portfolio, and set it up with the following code.

    function create_portfolio_post_type() {
    	$portfolio_labels = array(
    		'name' => 'Projects',
    		'singular_name' => 'Project',
    		'add_new' => 'Add New',
    		'all_items' => 'All Projects',
    		'add_new_item' => 'Add New Project',
    		'edit_item' => 'Edit Project',
    		'new_item' => 'New Project',
    		'view_item' => 'View project',
    		'search_items' => 'Search projects',
    		'not_found' => 'No projects found',
    		'not_found_in_trash' => 'No projects found in Trash',
    		'parent_item_colon' => 'Parent Project',
    		'menu_name' => 'Portfolio'
    	);
    
    	$portfolio_definition = array(
    		'labels' => $portfolio_labels,
    		'description' => 'Projects',
    		'public' => true,
    		'exclude_from_search' => false,
    		'show_ui' => true,
    		'show_in_nav_menus' => true,
    		'show_in_menu' => true,
    		'show_in_admin_bar' => true,
    		'menu_position' => 5,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'post-formats'),
    		'taxonomies' => 'project_type',
    		'has_archive' => true,
    		'rewrite' => array('slug', 'portfolio'),
    		'can_export' => true
    	);
    	register_post_type ('portfolio', $portfolio_definition);
    }
    add_action ('init', 'create_portfolio_post_type');

    Now let’s say I added a taxonomy to my post type with this code:

    function create_portfolio_taxonomy() {
    	$project_type_labels = array(
    		'name' => 'Project Types',
    		'singular_name' => 'Project Type',
    		'search_items' => 'Search Project Types',
    		'popular_items' => 'Popular Project Types',
    		'all_items' => 'All Project Types',
    		'parent_items' => 'Parent Project Type',
    		'parent_item_colon' => 'Parent Project Type',
    		'edit_item' => 'Edit Project Type',
    		'update_item' => 'Update Project Type',
    		'add_new_item' => 'Add New Project Type',
    		'new_item_name' => 'New Project Type Name',
    		'menu_name' => 'Project Types'
    	);
    
    	$project_type_definition = array(
    		'labels' => $project_type_labels,
    		'public' => true,
    		'show_in_nav_menus' => true,
    		'hierarchical' => true,
    		'rewrite' => array('slug' => 'projects'),
    		'capabilities' => array('manage_terms', 'edit_terms', 'delete_terms', 'assign_terms')
    	);
    	register_taxonomy ('project_type', 'portfolio', $project_type_definition );
    }

    What I want to do is set up my permalink structure so that if someone wants to get to a project, thy can type in:

    http://www.example.com/post_type(portfolio)/taxonomy(projects)/(taxonomy_item)animations/video1(post_name)/

    and get to the right post.

    However, when I use

    'rewrite' => array('slug' => 'portfolio/projects')

    in my taxonomy register function, the site returns a 404. What can I do to fix this?

    Also, yes, I did flush the rewrites.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Noel,

    I just posted a similar issue to this. Put this at the top of your 404 page and see where wordpress is ending up.

    <?php

    //get filtering params
    $params = array();
    global $query_string;
    $args = explode(“&”, $query_string);

    foreach($args as $value) {
    $query = explode(“=”,$value);
    $params[$query[0]] = urldecode($query[1]);
    }

    print_r($args);

    ?>

    For me it’s trying to go to index.php?attachment=category_name. WP is trying to find an attachment page that does not exist. Are you getting a similar error? If so I’ll post my fix here when I find it.

    Okay, so I have exactly the same issue. I’m struggling with this for days, i’m also facing the 404 with type attachment. @bkernan – did you already found a solution?

    Thanx!

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    @silvanlaroo, you can discuss that on your own thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multi-Level Permalinks on Custom Post Type’ is closed to new replies.