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',
);
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 ...
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 ( ...
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-&...
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( '...
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 ...
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 ...
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( '...
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' ...
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, ...
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.
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( '...
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 ...
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 ...
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');
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 ...
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,
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-...
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 ...
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 ...
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
...
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 ...
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 ...
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-{...
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' => ...
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; ...
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( ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
custom-post-type-archives × 443custom-post-types × 292
custom-taxonomy × 92
archives × 92
archive-template × 42
permalinks × 30
wp-query × 28
pagination × 24
categories × 23
url-rewriting × 23
php × 15
loop × 15
rewrite-rules × 15
templates × 14
page-template × 13
taxonomy × 12
menus × 11
functions × 10
pre-get-posts × 10
template-hierarchy × 9
plugins × 8
posts × 8
theme-development × 8
terms × 8
404-error × 8