A page that shows a list of a specific custom post type

I’ve created a custom post type called ‘product’. I want to add a page link to ‘products’ in the menu, but I don’t have that option.

I would like to know if there is a way of displaying it the same way as if it were like a category…
a page that shows all the ‘products’ like if they were posts, and that I could add to the menu.

Read More

At this stage I can only add specific ‘products’ but not a link to a list of them.

Any suggestions on how to make this work?

Related posts

Leave a Reply

2 comments

  1. In addition to @Rarsts answer, once you’ve created a custom post type with archive like this example:

    //* Create product custom post type
    add_action( 'init', 'register_product_custom_post_type' );
    function register_product_custom_post_type() {
    
    register_post_type( 'product',
        array(
            'labels' => array(
                'name'          => __( 'Product', 'wpsites' ),
                'singular_name' => __( 'Product', 'wpsites' ),
            ),
            'has_archive'  => true,
            'hierarchical' => true,
            'menu_icon'    => 'dashicons-portfolio',
            'public'       => true,
            'rewrite'      => array( 'slug' => 'product', 'with_front' => false ),
            'supports'     => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes' ),
            'taxonomies'   => array( 'product-type' ),
    
        ));
    
    }
    

    You can also control that archive using pre_get_posts.

    add_action( 'pre_get_posts', 'customize_custom_post_type_archive' );
    
    function customize_custom_post_type_archive( $query ) {
    if ( is_post_type_archive('product') && $query->is_main_query() )
    
        $query->set( 'posts_per_page', '6' );
        $query->set( 'order', 'ASC' );
    return $query;
    }
    

    You can then add your CPT archive link as a custom URL to your menu

    http://example.com/product/

  2. What you are looking for is custom post type archive. First you should make sure that your CPT is registered to have archive at all.

    Unfortunately natively WP doesn’t add CPT archives as available to be included in menus. The simplest solution is just to add custom link to it.

    There are also multiple snippets and plugins to address this floating around, from quick look up I have Post Type Archive Link bookmarked.