0

I know this question was brought up before, but I can't seem to get things working using any of the proposed solutions. This is how I have my custom post types and categories setup:

Custom Post Type: Buildings
-Buildings Categories:
--Medical
--Industrial
--Educational
--Recreational

-Buildings Regions (custom taxonomy):
--USA
---Connecticut
---New Jersey
---New York
--Canada
---Quebec
---Ontario

Every Building will be assigned to 1 building category (Medical, Industrial, etc) and 1 building region (USA->New York, Canada->Ontario, etc). This all works fine, except the permalinks to inner building pages are site.com/buildings/postname and there is no category archive for the custom post type categories. Here is what I'm trying to achieve:

  1. Permalinks to inner building pages to be example.com/buildings/category/postname

  2. Permalink to archive of all building pages to be example.com/buildings

  3. Permalinks to archives of each building category example.com/buildings/category

  4. Lastly I want to be able to display an archive of buildings by region. So example.com/buildings/region/usa would bring up all the buildings in the USA, while example.com/buildings/region/canada/quebec would bring up only buildings in Quebec, Canada.

I've tried numerous solutions, but the closest I was able to get was half of #1 working using the WP Permastructure plugin posted as an answer to this similar thread. I am able to get the permalinks for inner building pages to generate properly, but when accessed they return 404s.

Any help is greatly appreciated!

0

1 Answer 1

1

Yev, without a code sample to work from I'm not sure how helpful I can be but I'll give you the code that I use for creating Custom Post Types with a archive page. This example will get you started for an FAQ (easily modified).

Note the rewrite lines and the flush, which is what creates a permalink structure for the Custom Post Types (and flushes the cache to activate it). I suspect this will get you fairly close to what you're hoping for but if not, submit your code and I'll try to help.

if ( ! function_exists( 'new_cpt_faq' ) ) {
    function new_cpt_faq() {
        register_post_type( 'new_cpt_faq',
            array(
                'labels' => array(
                    'name' => __( 'FAQs', 'name_space'  ),
                    'singular_name' => __( 'FAQ', 'name_space'  ),
                    'add_new' => __( 'Add New FAQ', 'name_space'  ),
                    'add_new_item' => __( 'Add New FAQ', 'name_space'  ),
                    'edit_item' => __( 'Edit FAQ', 'name_space'  ),
                    'new_item' => __( 'New FAQ', 'name_space'  ),
                    'all_items' => __( 'All FAQs', 'name_space'  ),
                    'view_item' => __( 'View FAQ', 'name_space'  ),
                    'search_items' => __( 'Search FAQs', 'name_space'  ),
                    'not_found' =>  __( 'No FAQs found', 'name_space'  ),
                    'not_found_in_trash' => __( 'No FAQs found in Trash', 'name_space'  ),
                    'parent_item_colon' => '',
                    'menu_name' => __( 'FAQs', 'name_space'  )
                ),
            'public' => true,
            'has_archive' => true,
            'supports' => array( 'title', 'editor' ),
            'rewrite' => array(
                            'slug'=>'faqs',
                            'with_front'=> false,
                            'feed'=> true,
                            'pages'=> true
                        )
            )
        );

        flush_rewrite_rules();
    }
}
add_action( 'init', 'new_cpt_faq' );

if ( ! function_exists( 'new_cpt_faq_taxonomy_categories' ) ) {
    function new_cpt_faq_taxonomy_categories() {
        register_taxonomy(
        'new_cpt_faq',
        'new_cpt_faq',
        array(
            'labels' => array(
            'name' => __( 'FAQ Category', 'name_space'  ),
            'add_new_item' => __( 'Add New FAQ Category', 'name_space'  ),
            'new_item_name' => __( 'New FAQ Category', 'name_space' )
            ),
            'show_ui' => true,
            'show_tagcloud' => true,
            'hierarchical' => true
        )
        );
    }
}
add_action( 'init', 'new_cpt_faq_taxonomy_categories' );

http://codex.wordpress.org/Function_Reference/register_post_type

1
  • Thanks for your reply! How would you modify the code though to have archive pages for different FAQ categories?
    – Yev
    Feb 23, 2013 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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