Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Create a Custom Post Types Archive Page in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Create a Custom Post Types Archive Page in WordPress

Custom Post Types was one of the awesome features included in WordPress 3.0. One of our users asked us a question on twitter, how to create a custom post types archive page. We covered it in our initial article about Custom Post Types, but it wasn’t explained thoroughly. In this article, we will show you a step by step guide on how to create a custom post types archive page in WordPress.

First thing you need to make sure is that your custom post type has archive enabled in the code. To do this, you need to go to your custom post type code (can be found in your theme’s functions.php file or site-specific plugin file). You need to make sure that you have has_archive argument set to be true.

An example code would look like this:

add_action( 'init', 'create_post_type' );
function create_post_type() {
	register_post_type( 'deals',
			'labels' => array(
				'name' => __( 'Deals' ),
				'singular_name' => __( 'Deal' )
		'public' => true,
		'has_archive' => true,

Notice how we have has_archive set to be true in the array. You need to have this in your code. Once you do that, your custom post type will be assigned an archive page which can be accessed by going to a link like this:

Note: replace deals with whatever is the name of your custom post type.

WordPress by default uses the archive template of your theme to display the custom post type archive page. If you are ok with how the default archive looks, then you are done here. You have successfully created a custom post type archive page for your WordPress site.

However, if you want to create a custom archive page for your custom post type, then you would need to create a new file called archive-{posttype}.php. In our example, the file name would be archive-deals.php

The best way to start would be to copy the code from your theme’s archive.php file and paste it in your archive-{posttype}.php file. Then start tweaking from there. You can style this archive file to your heart’s desire. A very basic template would look like this:

if(have_posts()) : while(have_posts()) : the_post();
	echo '<div class="entry-content">';
	echo '</div>';
endwhile; endif;

Once you are done upload this file in your theme’s directory. After you have done that, you would see a custom archive page for your custom post type.

There you have it. You should now have a custom post types archive page in WordPress. For those who want to see custom examples, then you can see those by visiting our WordPress coupons page or our WordPress books page.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. dragoescu alin says:

    Hello, I just creat a new file archive for a new type. The name of new typw it’s firma.
    The archide page it’s call archive-firma.php . All run good but i realy don’t know where i can insert new php code.

    I want to add new code because i use ACF codes.
    please any help ?

    The page code it’s:

    the_archive_title( '’, ” );
    the_archive_description( ”, ” );

    __( ‘Previous page’, ‘twentysixteen’ ),
    ‘next_text’ => __( ‘Next page’, ‘twentysixteen’ ),
    ‘before_page_number’ => ” . __( ‘Page’, ‘twentysixteen’ ) . ‘ ‘,
    ) );

    // If no content, include the “No posts found” template.
    else :
    get_template_part( ‘template-parts/content’, ‘none’ );


  2. Rima says:

    It’s ammazing completely job .
    Congractulations .
    Can you please help me make my own archiving for the kids club .to save all things in safety way .
    Can you help me ??

  3. Essekia Paul says:

    I think, when working on really extensive websites with a lot of post types, taxonomies, terms, it is better to manage archives with something like the Elementary plugin.

    This also makes it easier to maintain / separate the content / design of archives.

  4. Hariharakumar says:

    My category archives for CPT are displaying in archive.php instead of archive-{CPT}.php what should i do now? please help

  5. Max says:

    WordPress files and their editing was just like a scare forest where i can’t find my desired code. PHP was just like a mountain that can’t be handled by me. but with this blog’s post give a confidence and a boost to start.
    Now i have hand on almost from installing to deploying WordPress website/blog.
    Thanks and Honors for Mr. Balkhi

  6. Jeremy says:

    what if I already have a page at yoursite/deals which has content on it. What would the url to my category’s archive page be?

  7. linx says:

    Never mind, i solved my problem by adding this to my functions.php

    function template_chooser($template)
    global $wp_query;
    $post_type = get_query_var(‘post_type’);
    if( $wp_query->is_search && $post_type == ‘member’ )
    return locate_template(‘archive-member.php’);
    return $template;
    add_filter(‘template_include’, ‘template_chooser’);

  8. linx says:

    i’ve created an archive-member.php and a search form to filter the results. however everytime my search includes the ‘s’ query string, it displays the results in the archive.php. eg:
    ?post_type=member&s=custom_post_title (displays results in archive.php)
    ?post_type=member&custom_taxonomy=developer (displays results in archive-member.php)

    i want all results that uses ?post_type=member to display in the archive-member.php.

    please help

  9. Niniko Kacharava says:

    Thanks so much for another simple and comprehensive post! You saved me tons of work once again!

  10. Davy says:

    Thanks, this is really helping me out!

    But I don’t get it the way I want it to. If I look at the examples given at the end, it looks quite similar to what I want to establish.

    I want to show 3 posts per row, with each post the title and thumbnail. When clicking on them there will be a pop-up window. (Html is ready for it so I only need to know how to set this up)

    This archive page is pretty much the same as I displayed my post in each category, but I’m getting stuck here..

    So how do I get this in to the php correctly?

    The page I made before, didn’t showed the posts but an link to archive….

    Can you help me out and tell me how the example pages work?
    They are quite similar to what I want.

    Thanks already,


  11. raul says:

    Hi there,

    Very helpful article. I’ll be trying it soon.
    I have a related question:

    Would you be able to somehow display the list of custom post archive pages, including not just the title of the pages, as you have it:
    • opinion
    • showcase
    • themes

    …but displaying also a featured image for each archive page, the way you can with post lists?

    • WPBeginner Support says:

      Yes sounds do able. One easier approach would be using featured images with the same name as custom post type then you can use something like:

      $args = array(
         'public'   => true,
         '_builtin' => false
      $output = 'names'; // names or objects, note names is the default
      $operator = 'and'; // 'and' or 'or'
      $post_types = get_post_types( $args, $output, $operator ); 
      foreach ( $post_types  as $post_type ) {
         echo '<img src="/path/to/images/' . $post_type . '.png" />';

      Needs improvement but we hope you get the idea.

  12. Jamshed says:

    Thanks a lot for this.

    It’s really helpful for me to understand the flow of custom post type and how to handle it!

    thanks again……

  13. Lorenzo says:

    Thanks for this tutorials.

    Is possible to display, a Title and Description in a archive-post_type.php page?

    I have lot of archive page in my site and I want to set a good SEO for this page.

    I have create all Custom Post Type with a Custom post type UI plugin and with a Yoast plugin now I can set all SEO option in all custom post type but not in archive page.

    Have a suggest for me?
    Thank you

    • Editorial Staff says:

      Yes you should be able to add an h1 tag with title and description in the template.

      • Lorenzo says:

        Thank you!

        I know this opportunity but I meant :

        with the and code? how I can insert?


        I have a network of blog for administrate multilanguage site (this site are not build by me, I had take this work of administration this site) and archive-post_type.php call a type of Custom Post Type that have the same name for EN site and DE site.

        If add the code inside the archive-post_type.php, the Title and the Description are only in one language and I can’t insert SEO for DE site.

        I know that my site is complicated and built bad but I can’t change this setting and I search a solution for insert SEO title, meta description and meta keyword in all languages that is made my site.

        You think that is impossible for my settings?

        • Lorenzo says:

          Sorry but the html code that I’ve written are deleted from site.

          in this paragraph : “with the and code? how I can insert?” I meant:

          – with the Title and <meta description code

        • Editorial Staff says:

          Use WPML plugin.

  14. Ifty says:

    Not working in version 3.5.1 . I got 404 error.

    • Editorial Staff says:

      Go to Settings » Permalinks. Then click save again. This should work then.

      • Shahriar says:

        “Go to Settings » Permalinks. Then click save again. This should work then.”

        It’s not working though I tried the way as you said. But same problem like IFTY. 404 error. I am using 3.5

      • Unknown Agent says:

        >Go to Settings » Permalinks. Then click save again. This should work then.

        Was also getting a 404 error and this solved it.

        Would never of fixed this other otherwise as such a massively illogical solution

        Thank you!

  15. jim lott says:

    To make pagination work you need to call the paged variable into your posts calls.

    query_posts( ‘post_type=xxxxxxx&post_status=published&posts_per_page=10&paged=” . get_query_var(‘paged’) ′);

  16. phpadam says:

    I can’t get this code to work. In fact, I spent hours with it. I’m not sure what global $query_string actually does, but the code will not work while that is in there. No posts display at all. It’s as though the query doesn’t return any results.

    If I replace this line: global $query_string; query_posts($query_string . “post_type=mentions&post_status=published&posts_per_page=10”);

    with this line query_posts( ‘post_type=mentions&post_status=published&posts_per_page=2’);

    I get results, but the pagination code does not work. The link changes from previous results to next results, but the result list does not change. The same posts are displayed on every page

  17. RyanMauroDesign says:

    @jmdocherty I’m looking for that answer as well. my ‘next’ and ‘previous’ links bring me to my 404 page.

  18. katarsis20032002 says:

    the code above don’t work for me

    the solution i was found there was in the codex

    For example, to set the display order of the posts without affecting the rest of the query string, you could place the following before The Loop:

    global $query_string; query_posts( $query_string . ‘&order=ASC’ );

    When using query_posts() in this way, the quoted portion of the parameter must begin with an ampersand (&)…

    the & is missing

    this is the original link

  19. jmdocherty says:

    +1 for “does anyone know how to get the ‘next’ and ‘previous’ links working”. Thanks for the great post though

  20. ValDes says:

    This really helped me out too. Any idea on how to get the prev and next links to work

  21. Mike says:

    Thanks for the post, how ever — Your method was returning all products from all categories. I modified it to retrieve only the products in the current category.

    $thisCat = get_category(get_query_var(‘cat’),false);

  22. sander says:

    Hi ,
    thanks for the tip!
    although i didnt get it working, until i deleted the “$query_string .” from the query_posts string.

    why is it in there?

    thanks again

    • Ramsey Stoneburner says:


      THANK YOU! for posting this! I was following the above tutorial and have been wracking my brain for several hours trying to get it to work. I decided to check the comments in case someone found anything and I got it working thanks to your comment!

    • Stephan Deglow says:

      same for me
      @sander thank you

      @wp-beginner: please edit the article and take out that damn $query_string thingy

      • Stephan Deglow says:

        @myself: check the wp codex before commenting.

        “When using query_posts() in this way, the quoted portion of the parameter must begin with an ampersand (&). ”

        and this is indeed the problem in the snippet provided above there is an ampersand missing:


        is the way to go..

        further reading:

  23. Ben Tremblay says:

    This is a nice step.
    For what I need? Half step.

    I’d love to use this for, say, posts that are parents, and posts that are their children.
    Catch is that a parent’s child can also have children, so that child is both child and parent. And if I can give that one both, I still have to keep the relationship straight … they aren’t apples and oranges in a barrel.

    But thanks!

  24. Darren Nickerson says:

    Interesting post, I will be trying this out in the near future. I have noticed the posts on this website really improving over the past couple of months, great job.

  25. ovidiu says:

    and a slightly simpler plugin with less features:

  26. ovidiu says:

    nice article but there is also a plugin out there caled: custom psot types archives: :-)

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.