I created a custom post type in WordPress and I can see all the posts on my archive page. But when I try to click on individual post links, I get a 404 error page. The URL seems to be getting duplicated somehow.
Here’s my custom post type code:
add_action('init', 'setup_gallery_type');
function setup_gallery_type(){
$gallery_settings = array(
'label' => _('Gallery'),
'singular_label' => _('Gallery Item'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type('gallery', $gallery_settings);
}
My template file looks like this:
<?php
/*
Template Name: Gallery Display
*/
get_header(); ?>
<?php
$query_params = array(
'post_type' => 'gallery',
'post_status' => 'publish'
);
$gallery_query = new WP_Query($query_params);
if($gallery_query->have_posts()) :
while($gallery_query->have_posts()) : $gallery_query->the_post();
?>
<h2><a href="<?php echo get_post_permalink() ?>"><?php echo the_title();?></a></h2>
<?php the_post_thumbnail('medium'); ?>
<?php the_excerpt(); ?>
<?php
endwhile;
else :
?>
<p>No gallery items found.</p>
<?php
endif;
get_footer();
?>
When I hover over a post title link, it shows: mysite.com/wp/gallery/summer-photos
But clicking it takes me to: mysite.com/wp/gallery/summer-photos/summer-photos/
Why is the slug getting repeated twice in the URL? How can I fix this single post view issue?