0

I have a custom post type

    // Set other options for Custom Post Type
    $args = array(
        'label'               => __( 'document', 'ecse' ),
        'description'         => __( 'Upload Documents', 'ecse' ),
        'labels'              => $labels,
        // Features this CPT supports in Post Editor
        'supports'            => array( 'title', 'editor', 'custom-fields', 'excerpt' ,'thumbnail','page-attributes','tags'),
        // You can associate this CPT with a taxonomy or custom taxonomy.
        'taxonomies'          => array( 'sources' ),
      'capability_type'     => 'page',

And I have custom taxonomies for it

register_taxonomy( 'sources',...[ ...  'has_archive' => true,
        'rewrite' => [
          'hierarchical' => true,
          "with_front" => false,
          'ep_mask' => EP_PERMALINK | EP_PAGES,
          'slug' => '/%sources%/'

register_taxonomy( 'forms', 'documents',[
      'has_archive' => true,
      'hierarchical' => true,
      'rewrite' => [
        'hierarchical' => true,
        "with_front" => false,
        'ep_mask' => EP_PERMALINK | EP_PAGES,
        'slug' => '/documents/%postname%/'
      ],
      'show_in_menu' => false,
      'query_var' => true,
    ]);

I'm able to get the archive page to display a paginated list of the post type.... But the permalink for the single post type is being malformed

The base for my taxonomy permalink is http://xxxx/documents/%sources%/ where sources is the taxonomy if I use http://xxxx/documents/%sources%/%postname%/ Then the single page works....but I lose the "archive pagination" thus http://xxxx/documents/%sources%/page/2/ doesn't work.

How do I get both sinlge and archive pages to work for custom post types?

  • What slug (documents?) and rewrite parameters are used in register_post_type()? – nmr Dec 17 '19 at 17:13
-1

WordPress can handle this automatically by creating a page called archive-CustomPostTypePage.php through register_post_type() function.

eg. archive-documents.php

You need to register your post type in the functions and the name has to be the same as the php file name above eg:

register_post_type('documents', array(
    // YOUR ARRAY HERE
));

Your Answer

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

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