I am trying to create a custom archive index page for a custom post type. I can't get it to work, I have followed this guide: https://codex.wordpress.org/Creating_an_Archive_Index.
Here's what I have been trying:
1. Created a custom post type:
function references(){
register_post_type('cows',
[
'labels' => [
'name' => __('Cows'),
'singular_name' => __('Cow'),
],
'public' => true,
'has_archive' => true,
'supports' => ['title', 'editor', 'thumbnail'],
'rewrite' => array(
'slug' => 'cows'
),
]
);
}
add_action('init', 'references');
2. Created a archive-cows.php
page for all the custom post type's posts.
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
the_title();
//
// Post Content here
//
} // end while
} // end if
3. Created a template called Cows in file: cows.php
/*
Template name: Cows
*/
get_header();
wp_get_archives(array(
'type' => 'monthly',
'post_type' => 'cows',
));
get_footer();
4. Created a new page (backend) and assigned it to template: Cows
At the moment WordPress is loading archive-cows.php
(because post type slug: cows and page template slug: cows), where I would like it to load cows.php
template file, and then in that template load the archives for cows (would not like to use a custom query without a archive page).