How to create an archive template for a custom post type?

I am using Metabox to create a Services custom post type. I am trying to create an archive template to display a list of all Services. The slug for the archive page should be /services/ but whenever I visit the URL it redirects me to the home page. Do I have the template set up properly?

In Metabox, I have the archive setting enabled.

In Bricks, I created a new template with the type of Archive. I set the following template conditions:

1 Like

I don’t use Metabox - so how you manage these settings I don’t know… but… there are some important items when defining a CPT:
has_archive => projectarchive,
(OR) has_archive => true,
rewrite => [ slug => projects, with_front => true ],

Either has_archive can be true, or the ‘slug’ of the archive page (which is then true and creates the slug you want).
And/Or rewrite creates the slug.
Then there should not be a page with the same url / slug - or it will clash. WP dynamically creates the archive.
Your archive template settings seem ok, so check if there’s already a page. Also, you can try going to menus, the name of the CPT, and ‘see all’. At the top is the link for the archive, add this to the menu.


This is for my CPT - called resources.
Then see if it works from the menu… and this lets you also check the URL/Slug - to see if something unexpected is going on.

2 Likes

Thank you! Adding the archive page to the menu still took me to the home page, so I dug through Metabox again and found that publicly queryable was set to false. Changing that fixed the problem.

So in Metabox, you have to have:

  • publicly queryable → ‘checked’
  • has archive → ‘checked’
4 Likes