theme development - Custom Post Type archive page listing a 404 or single post

admin2025-06-03  3

I want to preface this by saying we HAVE tried saving and re-saving the permalinks structure.

We are developing a custom theme and have a few custom post types in our theme. An example of one of them is below.

function broadcast_post_types() {
$labels = array(
    'name'               => 'Broadcasts',
    'singular_name'      => 'Broadcast',
    'menu_name'          => 'Broadcasts',
    'name_admin_bar'     => 'Broadcasts',
    'add_new'            => 'Add New Broadcast',
    'add_new_item'       => 'Add New Broadcast',
    'new_item'           => 'New Broadcast',
    'edit_item'          => 'Edit Broadcast',
    'view_item'          => 'View Broadcast',
    'all_items'          => 'All Broadcasts',
    'search_items'       => 'Search Broadcasts',
    'parent_item_colon'  => 'Parent Broadcasts:',
    'not_found'          => 'No Broadcasts found.',
    'not_found_in_trash' => 'No Broadcasts found in Trash.'
);

$args = array(
    'public'      => true,
    'labels'      => $labels,
    'description' => 'These broadcasts are a replay of Wisco Radio Content',
    'menu_icon'   => 'dashicons-format-video',
    'hierarchical'=> true,
    'has-archive' => true
);
register_post_type( 'broadcast', $args );

We run into a problem where when we try to visit this archive page (localhost/broadcast/), it either takes us to a single post (localhost/broadcast/post1) or a 404.

We have tried to reset the permalink setup and have ensured has-archive is set to true.

We are doing our local environment using MAMP and have a sandbox hosted online as well and this is happening at both locations. Any thoughts?

I want to preface this by saying we HAVE tried saving and re-saving the permalinks structure.

We are developing a custom theme and have a few custom post types in our theme. An example of one of them is below.

function broadcast_post_types() {
$labels = array(
    'name'               => 'Broadcasts',
    'singular_name'      => 'Broadcast',
    'menu_name'          => 'Broadcasts',
    'name_admin_bar'     => 'Broadcasts',
    'add_new'            => 'Add New Broadcast',
    'add_new_item'       => 'Add New Broadcast',
    'new_item'           => 'New Broadcast',
    'edit_item'          => 'Edit Broadcast',
    'view_item'          => 'View Broadcast',
    'all_items'          => 'All Broadcasts',
    'search_items'       => 'Search Broadcasts',
    'parent_item_colon'  => 'Parent Broadcasts:',
    'not_found'          => 'No Broadcasts found.',
    'not_found_in_trash' => 'No Broadcasts found in Trash.'
);

$args = array(
    'public'      => true,
    'labels'      => $labels,
    'description' => 'These broadcasts are a replay of Wisco Radio Content',
    'menu_icon'   => 'dashicons-format-video',
    'hierarchical'=> true,
    'has-archive' => true
);
register_post_type( 'broadcast', $args );

We run into a problem where when we try to visit this archive page (localhost/broadcast/), it either takes us to a single post (localhost/broadcast/post1) or a 404.

We have tried to reset the permalink setup and have ensured has-archive is set to true.

We are doing our local environment using MAMP and have a sandbox hosted online as well and this is happening at both locations. Any thoughts?

Share Improve this question asked Feb 5, 2019 at 7:44 WiscoRadioWiscoRadio 12 bronze badges 3
  • 4 It is has_archive and not has-archive.. – Sally CJ Commented Feb 5, 2019 at 8:19
  • Simple overlook - that's what it was. thanks @SallyCJ – WiscoRadio Commented Feb 5, 2019 at 17:02
  • You're welcome and don't forget to accept your answer. :) – Sally CJ Commented Feb 6, 2019 at 3:16
Add a comment  | 

1 Answer 1

Reset to default 0

Turns out I had has-archive instead of has_archive. After a permalink refresh, the archive page now appears.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748940700a315006.html

最新回复(0)