WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Index pages for custom post types (WP 3.1-RC1) (6 posts)

  1. theWebalyst
    Member
    Posted 3 years ago #

    I had created a custom post type (twec_product) with rewritten slug "product" before upgrading to 3.1 RC. I then upgraded to 3.1 RC1 in order to test the new "index pages for custom post types" feature.

    The following is a URL for one of my custom products:
    http://thewebalyst.com/products/wordpress-website-set-up-launch-package/

    From ticket 13818 I assumed the following URL should automatically provide an index of my products: http://thewebalyst.com/products/

    As does every obvious URL variant I could think of.

    Have I misunderstood what functionality is supposed to be here?

    If not, how can I have a custom post type, with 'slug' rewritten as "products" and this not work?

    Here is the code in the plugin I used to enable this post type (set up in WP 3.0.2, now upgraded to WP 3.1 RC1):

    function create_post_type() {
      register_post_type( 'twec_product',
        array(
          'labels' => array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'Product' )
          ),
          'public' => true,
          'rewrite' => array('slug' => 'products')
        )
      );
    }
    
    add_action( 'init', 'create_post_type' );
  2. Andrew Nacin
    Lead Developer
    Posted 3 years ago #

    You're missing has_archive => true.

  3. theWebalyst
    Member
    Posted 3 years ago #

    Thanks Andrew but it still does not find http://thewebalyst.com/products/

    I now have the following (is this what you meant?)

    function create_post_type() {
      register_post_type( 'twec_product',
        array(
          'labels' => array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'Product' )
          ),
          'public' => true,
          'has_archive' => true,
          'rewrite' => array('slug' => 'products')
        )
      );
    }
  4. Dion Hulse
    WordPress Dev
    Posted 3 years ago #

    Have you flushed your rewrite rules after making the change? Saving the rules on the Permalinks page will suffice.

  5. theWebalyst
    Member
    Posted 3 years ago #

    Ahah! Sorted, thanks guys. So much to learn here :-) and so much undocumented.

    Would be good if the has_archive line was in the sample in the Custom Post Types docs (http://codex.wordpress.org/Custom_Post_Types) so I shall put this forward.

  6. Andrew Nacin
    Lead Developer
    Posted 3 years ago #

    I'll be updating the Custom Post Types page with all the new 3.1 goodies soon.

Topic Closed

This topic has been closed to new replies.

About this Topic