WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type Archive Template Not Working (10 posts)

  1. Justin Carroll
    Member
    Posted 3 years ago #

    Here's my code for the custom post type:

    function create_post_type() {
    	register_post_type( 'galactic_gallery',
    		array(
    		'labels' => array(
    			'name' => __( 'Gallery' ),
    			'singular_name' => __( 'Gallery Post' ),
    		),
    		'rewrite' => array( 'slug' => 'gallery', 'with_front' => false ),
    		'public' => true,
    		'menu_position' => 4,
    		'has_archive' => true,
    		'hierarchical' => true,
    		'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
    		'taxonomies' => array( 'post_tag', 'category'),
    		)
    	);
    	flush_rewrite_rules( false );
    }
    add_action( 'init', 'create_post_type' );

    I have single post template called single-galactic_gallery.php and that works. I have a page called archive-galactic_gallery.php and my gallery posts, when I click on a tag or a category, are not going there. Any help would be appreciated. Thanks!

  2. Justin Carroll
    Member
    Posted 3 years ago #

    Maybe since I'm using taxonimies of 'post_tag' and 'category' which are also being used by posts when I click on the category or tag for a custom post type it's using the default index.php for that?

  3. cschuster
    Member
    Posted 3 years ago #

    I have the same query and custom post type setup and am having the exact same problem. Can't figure it out. Have you gotten a response to your issue through another forum?

  4. chiragkalani
    Member
    Posted 3 years ago #

    I also have a same problem. waiting for reply.

  5. Kerri Dawe
    Member
    Posted 2 years ago #

    same issue here

  6. Justin Carroll
    Member
    Posted 2 years ago #

    I wrote a definitive post about custom post type pagination over at wptuts, check it out!

  7. Kerri Dawe
    Member
    Posted 2 years ago #

    adding 'has_archive' => true when I register my post type as mentioned here solved my problems.

  8. egorpromo
    Member
    Posted 2 years ago #

    I've read this topic and I can't resolved same problem.
    I have functions.php with code:

    add_action( 'init', 'create_zombie_post_type' );
    function create_zombie_post_type()
    {
    	register_post_type('zombies',
    		array(
    			'label' => 'Zombies',
    			'public' => true,
    			'has_archive' =>true
    		)
    	);
    }

    I have single template called single-zombies.php and that works.
    I have archive.php template and archive-zombies.php template. I have permalinks in Custom Structer like /%postname%/. I try URL http://localhost/wordpress/zombies and It is not working because I see 404 page.
    Where is my mistake? Have I problem with URL or code inside functions.php?

  9. function create_zombie_post_type() {
    	register_post_type( 'zombies',
    		array(
    		'labels' => array(
    			'name' => __( 'Zombies' ),
    			'singular_name' => __( 'Zombie Post' ),
    		),
    		'rewrite' => array( 'slug' => 'zombies', 'with_front' => true ),
    		'public' => true,
    		'has_archive' => true,
    
    		)
    	);
    	flush_rewrite_rules( false );
    }
    add_action( 'init', 'create_zombie_post_type' );
  10. AngelEyes
    Member
    Posted 2 years ago #

    Thanks for that Ipstenu.

    flush_rewrite_rules(false); --- this is something you need to include whenever you create a custom post type with an archive?

Topic Closed

This topic has been closed to new replies.

About this Topic