Skip to main content
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.7k
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,537
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,238
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

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

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,921
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
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.8k
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

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,575
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
  • 681
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
  • 60k
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

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
Accepted

Add Settings to Custom Post Type

Ok, so I got annoyed with it not working and decided to just rewrite it. I'm not sure what the solution was, but I suspect two things: the wrong endpoint for the form (should be options.php) and the ...
dotZak's user avatar
  • 68
2 votes
Accepted

Conditional tags don't work

is_singular will return false on an archive page. If you wanted to check if you are on an archive for a post type, you would use is_post_type_archive( 'libri' ) , or you can create an archive-{...
czerspalace's user avatar
  • 1,721
2 votes
Accepted

Not able to see CPT archive template

I set my system up with the exact same as your code above. I get the same results. What I did to fix it was change your line 'rewrite' => array( 'slug' => 'articles', 'with_front' => ...
rudtek's user avatar
  • 6,238
2 votes
Accepted

How to group by taxonomy on Custom Post Type archive

You're almost there. Since the_title inside your custom loop is one of the Post template tags you need to assign the global $post to use the new data from the custom query. <?php global $post; ...
Den Isahac's user avatar
2 votes
Accepted

How to hyperlink content from archive page with custom post-type

use the_permalink or get_the_permalink to display/retrieve the URL of a post ( a post of any type, they're all the same internally ) e.g. the_permalink(); orx <a href="<?php echo esc_url( ...
Tom J Nowell's user avatar
  • 60k
2 votes
Accepted

is_main_query() not working for WP REST API

To answer the question directly - The REST API do not initialize a main query, therefor there should not be any for requests coming that way. What you should do is to create your own end point and ...
Mark Kaplun's user avatar
  • 23.5k
2 votes

How to remove current year from wp_get_archives

As you can see from the source code of wp_get_archives (line 1791 currently) the query is hardcoded. There is no filter to influence it. This means you have to correct the result afterwards. This is ...
cjbj's user avatar
  • 14.8k
2 votes
Accepted

Custom post type archive sorted and grouped by date in post meta field

OK, so this problem has two parts: Make WordPress to sort these posts properly. Make WordPress to display them with all that grouping. 1. Sorting CPT by meta value on archive You can use ...
Krzysiek Dróżdż's user avatar

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