WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Create a Custom Post Types Archive Page in WordPress

How to Create a Custom Post Types Archive Page in WordPress

Last updated on February 25th, 2013 by Editorial Staff
105 Shares
Share
Tweet
Share
Pin
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',
		array(
			'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:

http://yoursite.com/deals/

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:

<?php
get_header();
if(have_posts()) : while(have_posts()) : the_post();
	the_title();
	echo '<div class="entry-content">';
	the_content();
	echo '</div>';
endwhile; endif;
get_footer();
?>

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.

105 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

46 Comments

Leave a Reply
  1. Carrie Lewis says:
    Apr 6, 2019 at 10:49 pm

    I have a quick question. I am trying to build a FAQ page and I would like just the questions to show on the main archive page and not the content. So when they click on the questions it will take them to the content page itself.

    Also is there a way to not show the authors name in the posted content. I am not a programmer but am learning. Thanks. :-)

    Reply
    • WPBeginner Support says:
      Apr 8, 2019 at 12:54 pm

      For the FAQ you may want to take a look at our article here: https://www.wpbeginner.com/plugins/how-to-add-a-frequently-asked-questions-faqs-section-in-wordpress/

      For removing the author name you would want to take a look at our article here: https://www.wpbeginner.com/wp-themes/how-to-remove-author-name-from-wordpress-posts/

      Reply
  2. Sunny Singh says:
    Oct 11, 2018 at 7:01 am

    What would be the URL to access the archive page?

    Reply
  3. Monique says:
    May 18, 2017 at 1:10 pm

    Everything works but how do you give your custom post type another design as your other posts? Can you use it with a single.php file that sends each post to its own single-[tag or category].php file? I tried this out and get the right single post URL in the location bar but the wrong content on the page.

    Reply
  4. dragoescu alin says:
    Sep 28, 2016 at 6:38 am

    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:

    <?php
    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’ );

    endif;
    ?>


    Reply
  5. Rima says:
    May 16, 2016 at 11:23 am

    Hello
    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 ??

    Reply
  6. Essekia Paul says:
    May 3, 2016 at 2:37 am

    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.

    Reply
  7. Hariharakumar says:
    Feb 26, 2016 at 10:19 am

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

    Reply
    • Rafael Cavalcante says:
      Apr 25, 2017 at 3:28 pm

      Replace {CPT} with the name of your custom post type.

      IE.:
      For “register_post_type(‘brand’)”, your template will be archive-brand.php

      Reply
  8. Max says:
    Dec 21, 2015 at 5:28 am

    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

    Reply
  9. Jeremy says:
    Jan 15, 2015 at 1:21 pm

    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?

    Reply
    • Jouke Nienhuis says:
      Jun 11, 2017 at 8:01 am

      You must not think in real internetlinks or URI as they are called. In WordPress you have an option to rewrite the url, so that it links directly to the post name or category archive. In the address bar, you normally see an address pointing to a file, or if you have it directed to a directory, like it looks in your example, it can take its index.html or index.php file in that directory. But in a WordPress site that address is cloaked and in reality it takes you to archive-deals.php. So no conflicts here. You have to change the thinking form normal linking to an address to a WordPress linking.

      Reply
  10. linx says:
    Sep 4, 2014 at 7:15 am

    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’);

    Reply
    • RHUT says:
      May 7, 2015 at 7:56 am

      How to create drop down select box for custom post type category and subcategory.

      Reply
  11. linx says:
    Sep 4, 2014 at 6:41 am

    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

    Reply
  12. Niniko Kacharava says:
    Apr 24, 2014 at 3:04 am

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

    Reply
  13. Davy says:
    Jan 10, 2014 at 3:18 am

    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,

    Davy

    Reply
    • Damon says:
      Aug 14, 2018 at 6:21 pm

      Hey bud Try Pods for this and create archive page, and re-write it with the template.

      Reply
  14. raul says:
    Nov 6, 2013 at 10:54 am

    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?

    Reply
    • WPBeginner Support says:
      Nov 6, 2013 at 7:02 pm

      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:

      <?php
      
      $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.

      Reply
  15. Jamshed says:
    May 14, 2013 at 6:46 am

    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……

    Reply
  16. Lorenzo says:
    Apr 3, 2013 at 4:33 am

    Hi,
    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
    Lorenzo

    Reply
    • Editorial Staff says:
      Apr 3, 2013 at 2:19 pm

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

      Reply
      • Lorenzo says:
        Apr 4, 2013 at 5:49 am

        Thank you!

        I know this opportunity but I meant :

        with the and code? how I can insert?

        and

        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?

        Reply
        • Lorenzo says:
          Apr 4, 2013 at 6:23 am

          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:
          Apr 10, 2013 at 10:51 am

          Use WPML plugin.

  17. Ifty says:
    Mar 30, 2013 at 2:31 am

    Not working in version 3.5.1 . I got 404 error.

    Reply
    • Editorial Staff says:
      Apr 1, 2013 at 8:36 am

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

      Reply
      • Shahriar says:
        Apr 22, 2013 at 10:00 am

        “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

        Reply
      • Unknown Agent says:
        Mar 10, 2014 at 10:36 pm

        >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!

        Reply
  18. jim lott says:
    Jul 25, 2012 at 7:58 am

    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’) ′);

    Reply
    • Kyle says:
      Aug 7, 2012 at 10:22 am

      Works like a charm – thanks dude

      Reply
  19. phpadam says:
    Nov 22, 2011 at 12:37 pm

    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

    Reply
  20. RyanMauroDesign says:
    Aug 12, 2011 at 11:15 am

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

    Reply
  21. katarsis20032002 says:
    Jul 22, 2011 at 2:26 pm

    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

    http://codex.wordpress.org/Function_Reference/query_posts

    Reply
  22. jmdocherty says:
    Jul 4, 2011 at 12:35 pm

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

    Reply
  23. ValDes says:
    May 26, 2011 at 2:15 pm

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

    Reply
  24. Mike says:
    Apr 26, 2011 at 4:16 pm

    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);
    query_posts(“post_type=product&post_status=publish&posts_per_page=10&cat=”.$thisCat->cat_ID);

    Reply
  25. sander says:
    Dec 28, 2010 at 10:09 am

    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

    Reply
    • Ramsey Stoneburner says:
      Jan 31, 2011 at 12:13 am

      @sander

      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!

      Reply
    • Stephan Deglow says:
      Oct 13, 2012 at 8:57 am

      same for me
      @sander thank you

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

      Reply
      • Stephan Deglow says:
        Oct 13, 2012 at 9:03 am

        @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:

        query_posts(“&post_type

        is the way to go..

        further reading: http://codex.wordpress.org/Function_Reference/query_posts

        Reply
  26. Ben Tremblay says:
    Aug 31, 2010 at 9:00 pm

    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!

    Reply
  27. Darren Nickerson says:
    Aug 31, 2010 at 7:01 pm

    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.

    Reply
  28. ovidiu says:
    Aug 31, 2010 at 2:00 pm

    and a slightly simpler plugin with less features: http://wordpress.org/extend/plugins/simple-custom-post-type-archives/

    Reply
  29. ovidiu says:
    Aug 31, 2010 at 1:56 pm

    nice article but there is also a plugin out there caled: custom psot types archives: http://ratvars.com/custom-post-type-archives :-)

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
RafflePress - WordPress Giveaway and Contest Plugin
RafflePress
Giveaway and Contest Plugin for WordPress. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 25 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2019 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2019)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2019)
    • SiteGround Reviews from 1032 Users & Our Experts (2019)
    • Bluehost Review from Real Users + Performance Stats (2019)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • 7 Best CRM Software for Small Businesses (Compared)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2019 – Step by Step Guide
Deals & Coupons (view all)
Weglot Coupon
Get 15% OFF on Weglot multilingual plugin for WordPress.
Webnus
Webnus Coupon
Get 20% OFF on Webnus themes and plugins for WordPress.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress

Copyright © 2009 - 2019 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by HostGator | WordPress CDN by MaxCDN | WordPress Security by Sucuri.