I am using Wordpress 5.4. I created a CPT using the code below:
$args = array(
'labels' => $labels,
'description' => 'Some description',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
);
register_post_type( 'article', $args );
has_archive
was set to true and my understanding is that now when I goto /articles
I am supposed to see all posts of type article
. But that is not the case. When I goto /articles
I see my normal posts. I do not have any article-archive.php
on my system and understand that is not necessary. I do have a ./wp-content/themes/twentynineteen/archive.php
and I am using a child theme of twnetynineteen
on my site.
How can I fix this?
EDIT:
- I have tried
/article
and it does not fix the problem. - I have tried resaving permalinks (Settings->Permalinks) and it does not fix the problem.
- The code above is located in a plugin.
- I can see my article if I goto
/?article=test-article
wheretest-article
is slug of my article. - I am using
nginx
with this configuration.
I am using Wordpress 5.4. I created a CPT using the code below:
$args = array(
'labels' => $labels,
'description' => 'Some description',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
'has_archive' => true,
);
register_post_type( 'article', $args );
has_archive
was set to true and my understanding is that now when I goto /articles
I am supposed to see all posts of type article
. But that is not the case. When I goto /articles
I see my normal posts. I do not have any article-archive.php
on my system and understand that is not necessary. I do have a ./wp-content/themes/twentynineteen/archive.php
and I am using a child theme of twnetynineteen
on my site.
How can I fix this?
EDIT:
- I have tried
/article
and it does not fix the problem. - I have tried resaving permalinks (Settings->Permalinks) and it does not fix the problem.
- The code above is located in a plugin.
- I can see my article if I goto
/?article=test-article
wheretest-article
is slug of my article. - I am using
nginx
with this configuration.
2 Answers
Reset to default 1has_archive was set to true and my understanding is that now when I goto /articles I am supposed to see all posts of type article.
Nowhere in your code is articleS mentioned, the slug of the post type is article
, so the URL of its archive should be /article/
. If you want it to be articles
you have to say so.
In this case, it's the classic mistake of registering a post type or taxonomy, but not flushing permalinks to add their rules. Go to the permalinks setting page, and resave.
As for the template archive.php
, this is irrelevant to wether the page loads or not. The template hierarchy will fallback to index.php
which is required for a theme if no other templats are found. Additionally, archive.php
doesn't make the URL an archive. The URL makes it an archive, and the fact it's an archive makes WP load that template. WP has already figured out what posts to fetch before the template is chosen.
The solution to this problem is to use Post name in /wp-admin/options-permalink.php
.
/article/
not/articles/
. The defaultarchive.php
file should be able to display your articles. – Shazzad Commented Apr 12, 2020 at 20:16/article
also does not work – morpheus Commented Apr 12, 2020 at 21:12/?p=123
in/wp-admin/options-permalink.php
– morpheus Commented Apr 13, 2020 at 16:20