I have a custom post type called 'our-clients'. Create a document 'archive-our-clients.php' and when I place in the URL ' link ' it shows me the index.
plugin
function our_clients(){
$labels = array(
'name' => 'Our Clients',
'singular_name' => 'Our Client'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array(
'title',
'thumbnail',
'editor',
'revisions'),
'menu_position' => 4,
'exclude_from_search' => true,
'menu_name' => 'Our Clients',
'menu_icon' => 'dashicons-star-filled',
'can_export' => true
);
register_post_type('our-clients', $args);
}
add_action('init', 'our_clients');
archive-our-clients.php
<?php
$args = array(
'post_type'=>'our-clients',
'posts_per_page' => -1,
'post_status' => 'publish'
);
// The Query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<h2><?php echo the_title(); ?></h2>
<?php
}
wp_reset_postdata();
}
?>