Skip to main content
Share Your Experience: Take the 2024 Developer Survey
33 votes
Accepted

Adding a menu item for a Custom Post Archive

You can use a built in function of the menu editor for this. Go to your Custom Post Type in the Menu editor, click the "view all" tab and the first item you see is a link to the CPT archive page. In ...
Florian's user avatar
  • 1,575
16 votes
Accepted

How to rewrite slug of custom post type archive page

Pass the desired archive slug via has_archive: $args = array( 'rewrite' => array( 'slug' => 'case-studies' ), 'has_archive' => 'testimonials-case-studies', );
Milo's user avatar
  • 78.5k
11 votes
Accepted

Page Template as Custom Post Type Archive

Since WordPress version 4.4 the hook 'theme_page_templates' allows to set arbitrary page templates. It means that it's possible to show arbitrary values in the "Page Template" menu of the page edit ...
gmazzap's user avatar
  • 46.2k
6 votes

Get custom post type slug for an archive page

The answers get confusing. And maybe Im as well but the headline question is: Get custom post type slug for an archive page If you mean post type archive landing-page, and when ...
cavameta's user avatar
  • 183
6 votes

Custom Post Type - Archive page title

You can add a filter in the file functions.php of your template. It modify the archive page meta title of the custom post type 'myCPT' function new_cpt_archive_title($title){ if ( ...
Raph's user avatar
  • 61
6 votes
Accepted

Change number of posts to show on Archive page (custom post type)

Just make sure you're not in the admin when changing the query: function num_posts_archive_project_ie($query) { if (!is_admin() && $query->is_archive('projects-ie') && $query-&...
janh's user avatar
  • 2,738
6 votes
Accepted

Is it possible to remove the posts_per_page limit on a specific post type?

You can hook into the pre_get_posts action, to access the $query object. You should use your action hook inside your functions.php. An example of what your function could look like: add_action( '...
FFrewin's user avatar
  • 238
5 votes

Custom Post Type Archive template page not found

I don't think you need to use the hook pre_get_posts on this. Remove that part from functions.php. Then just put the archive-technology.php in themes root directory. Then go to you Permalinks settings ...
CodeMascot's user avatar
  • 4,527
4 votes

Custom Post Type archive giving 404

I had this problem and tried all the solutions (flush permalinks, various rewrites, etc) until I stumbled in the WP Codex on query_var (boolean or string) (optional) False to disable the ...
user3445853's user avatar
4 votes

taxonomy template for custom post type the same as the archive

Thanks for Milo's pointer function department_template( $template = '' ) { if (is_tax('department') ) { $template = locate_template( 'archive-team.php' ); } return $template; } add_filter( '...
Chris Pink's user avatar
4 votes
Accepted

Custom Post Archive is not working

why don't you try adding: 'has_archive' => true, to your code? so replace this line: 'public' => true, with this: 'public' => true, 'has_archive' ...
rudtek's user avatar
  • 6,121
4 votes
Accepted

pre_get_posts with tax_query causes empty result

You use tax_query incorrectly. Take a look at Codex Page tax_query should be an array which can contain: relation - it should be string (AND/OR) taxonomy term - array with defined taxonomy, field, ...
Krzysiek Dróżdż's user avatar
3 votes
Accepted

Custom taxonomy template not working with simple loop. Multiple CPT using the same taxonomy

WP defaults to showing normal native Posts in archives. It won't automagically pick up which post types you want in your archive. You will have to adjust main query for it to explain that to it, with ...
Rarst's user avatar
  • 99.7k
3 votes

Meta_Query as a way how to setup CPT permalinks - is it a good thing?

Since it is a performance question, you might be able to avoid using meta keys at all by storing/getting that data another way and not having to set a separate meta field to match with... a. You ...
majick's user avatar
  • 5,081
3 votes

How can I give CPT archive correct body class?

There's filter called body_class for that. function my_own_body_classes($classes) { // Add Classes to body if the post type archive is 'publikasjoner' if ( is_post_type_archive( '...
Abhik's user avatar
  • 2,911
3 votes

"Sticky" posts for each category (archive.php)

I cannot comment Pieter Goosen's answer due to reputation rules /-: The current code has a side-effect on current wordpress 4.8 (March 2018), it shows sticky posts when accessing a non-existing page ...
bz-mof's user avatar
  • 31
3 votes

Get custom post type slug for an archive page

You can use this code and this code is working for me, $t_slug = get_query_var('term');
Navin Bhudiya's user avatar
3 votes
Accepted

Set featured image to archive.php

In my opinion the right way to do this is to create theme options. Create a field asking the desired image for the clients post type archive.
Laxmana's user avatar
  • 1,332
3 votes
Accepted

Custom post type search with slug in URL

On the form, change action="<?php echo site_url('/'); ?>" To: action="<?php echo esc_url( get_post_type_archive_link( 'club_societies' ) ); ?>" Where 'club_societies' is the slug of ...
Jacob Peattie's user avatar
3 votes

Add parent post to Custom Post Type

Setting the hierarchical property of the post type to true let’s you set parent posts for them: 'hierarchical' => true,
Jacob Peattie's user avatar
3 votes

Custom post type archive with page as parent url

Yes. First, unregister the post type. (None of the actual data will be deleted if you already have posts.) Then, re-register it with 'rewrite' => array('slug' => 'page-name/custom-post-type-...
WebElaine's user avatar
  • 9,430
3 votes

Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters

<?php echo substr(get_the_title(), 0,42) ;?> Notice the echo and the get_the_title() This will get you the result you're looking for. Here's an alternative to consider: I've always found ...
Faye's user avatar
  • 671
3 votes
Accepted

What's the name of the custom post type yearly archive template?

CPT's don't have date archives, those are a post specific feature. Having said that, nothing prevents you building a custom bespoke date archive for a CPT. Just don't expect WordPress core to do it ...
Tom J Nowell's user avatar
  • 59.4k
3 votes
Accepted

Array_search ignoring the first element

In PHP, the number 0 is interpreted as false-ish. Your if-statement asks for a true-ish condition like this: If the result of the array_search function is interpreted as true-ish, THEN do the stuff ...
HU is Sebastian's user avatar
2 votes

Get custom post type slug for an archive page

t should be noted that if has_archive is set to true while registering the Custom Post Type, the post type archive /cptslug/ will be internally rewritten to ?post_type=cptslug. So this would also mean ...
majick's user avatar
  • 5,081
2 votes

Second Custom Post Type Archive

I had this same issue of needing two archive pages for a custom post type. I was able to accomplish this fairly cleanly using four WP hooks For the example my custom post type is "member". I need a ...
Techlands's user avatar
2 votes

Page Template as Custom Post Type Archive

gmazzap's answer is great! I'd just like to add that since 4.1 there are two new functions that perfectly fit that use case: the_archive_title and the_archive_description. For themes that already use ...
kraftner's user avatar
  • 5,608
2 votes

Editable content on a Custom Archive page

You can try to build some options custom page to allow users to change some text. there are many plugins for easily creating that functionality. I will suggest you the most popular - ACF - Options ...
Narek Zakarian's user avatar
2 votes

Editable content on a Custom Archive page

You can use Options API or Setting API to store the data in the database. Write a plugin to create a meta box for the introduction text and show that text on the archive-unicorn.php. Or you can ...
Max Yudin's user avatar
  • 6,297
2 votes
Accepted

How do I get the permalink structure to work like this?

You can accomplish this with add_rewrite_rule(). I personally like to show this example in a class to make it copy/paste ready. You could throw this in a plugin or functions.php -- some place that ...
jgraup's user avatar
  • 9,754

Only top scored, non community-wiki answers of a minimum length are eligible