Custom post type – archive

I have custom post type for wordpress.

http://localhost/wordpress/photos/
http://localhost/wordpress/photos/my-photo

Why these url return 404 not found ?

Read More

How can I make a archive file for this ?
like :

archive-photos.php ( I have this in directory, but …)

function register_gallery(){
    register_post_type( 'photos', array(
        'public'            => true,
        'menu_position'     => 10,
        'menu_icon'     => 'dashicons-format-gallery',
        'supports'      => array( 'title', 'editor', 'thumbnail'),
        'has_archive'       => true,

    ));
}

add_action('init','register_gallery');

Related posts

2 comments

  1. I found another solution, it can be done on 404 page when navigating through archives on custom post type(CPT):

    /**
     * My cpt is storytitle and slug for cpt is story-title
     * 
    **/
    function generate_cpt_rewrite_rules( $wp_rewrite ) {
    
    $event_rules = array(
    'story-title/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?post_type=storyTitle&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
    'story-title/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?post_type=storyTitle&year=$matches[1]&monthnum=$matches[2]',
    'story-title/([0-9]{4})/?$' => 'index.php?post_type=storyTitle&year=$matches[1]'
    );
    
    $wp_rewrite->rules = $event_rules + $wp_rewrite->rules;
    }
    add_filter( 'generate_rewrite_rules', 'generate_cpt_rewrite_rules' );
    

Comments are closed.