0

I have to declare two custom post type in my theme. But when declaring the second post type which is overwriting the permalink of first post type and rendering 404 error page :(

Please find my declartions below Post type : Projects

$labels = array(
        'name' => __('Projects', ET_DOMAIN) ,
        'singular_name' => __('Project', ET_DOMAIN) ,
        'add_new' => _x('Add New project', ET_DOMAIN, ET_DOMAIN) ,
        'add_new_item' => __('Add New project', ET_DOMAIN) ,
        'edit_item' => __('Edit project', ET_DOMAIN) ,
        'new_item' => __('New project', ET_DOMAIN) ,
        'view_item' => __('View project', ET_DOMAIN) ,
        'search_items' => __('Search Projects', ET_DOMAIN) ,
        'not_found' => __('No Projects found', ET_DOMAIN) ,
        'not_found_in_trash' => __('No Projects found in Trash', ET_DOMAIN) ,
        'parent_item_colon' => __('Parent project:', ET_DOMAIN) ,
        'menu_name' => __('Projects', ET_DOMAIN) ,
    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => true,

        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 5,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => ae_get_option('fre_project_archive', 'projects') ,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => array(
            'slug' => 'project','with_front' => FALSE
        ) ,
        'capability_type' => 'post',
        'supports' => array(
            'title',
            'editor',
            'author',
            'thumbnail',
            'excerpt',
            'custom-fields',
            'trackbacks',
            'comments',
            'revisions',
            'page-attributes',
            'post-formats'
        )
    );
    register_post_type(PROJECT, $args);

Post type : Carry

$labels = array(
        'name' => __('Carry', ET_DOMAIN) ,
        'singular_name' => __('Carry', ET_DOMAIN) ,
        'add_new' => _x('Add New Carry', ET_DOMAIN, ET_DOMAIN) ,
        'add_new_item' => __('Add New Carry', ET_DOMAIN) ,
        'edit_item' => __('Edit carry', ET_DOMAIN) ,
        'new_item' => __('New carry', ET_DOMAIN) ,
        'view_item' => __('View carry', ET_DOMAIN) ,
        'search_items' => __('Search carry', ET_DOMAIN) ,
        'not_found' => __('No Projects found', ET_DOMAIN) ,
        'not_found_in_trash' => __('No carry found in Trash', ET_DOMAIN) ,
        'parent_item_colon' => __('Parent carry:', ET_DOMAIN) ,
        'menu_name' => __('Carry', ET_DOMAIN) ,
    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => true,

        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 5,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => ae_get_option('fre_carry_archive', 'carry') ,
        'query_var' => 'carry',
        'can_export' => true,
        'rewrite' => array(
            'slug' => ae_get_option('fre_carry_slug', 'carry'),'with_front' => FALSE
        ) ,
        'capability_type' => 'post',
        'supports' => array(
            'title',
            'editor',
            'author',
            'thumbnail',
            'excerpt',
            'custom-fields',
            'trackbacks',
            'comments',
            'revisions',
            'page-attributes',
            'post-formats'
        )
    );
    register_post_type(CARRY, $args);

For all post under Carry and Projects type the permalink showing carry while changing the permalink to anyother from default structure.

Example:

Post title - "I am from Carry" under Carry type and "I am from Projects" under Projects type but URL will like follows,

http://exaple.com/carry/i-am-from-carry

http://exaple.com/carry/i-am-from-projects instead of http://exaple.com/projects/i-am-from-projects

Please help me to identify the issue. Any help will be greatly appreaciated

  • You are using constants that are not defined in your code, like PROJECT or `CARRY' . What those constant are? Also, are you flushing the rewrite rules after the custom post types registration? One more note: custom post types shouldn't be registered by themes; better do it in plugins or you will loose data if you change theme. – cybmeta Oct 26 '15 at 9:59
  • PROJECT and CARRY used instead of projects and carry post type respectivly – Aadi Oct 26 '15 at 10:37

Your Answer

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

Browse other questions tagged or ask your own question.