I created a very small plugin using a Custom Post Type.

This is NOT a commercial or publicly available plugin, only my website is using it.

What happens:

  1. when I click the name of a user who posted a post, I should eventually get a page containing the list of the titles of the posts he posted: I get a 404 page;

  2. when I click any monthly archive of posts I get a 404 page, EXCEPT when a document of my custom post type is present in the list;

When I disable my plugin, 404 error goes away.

I red anything about flushing permalinks, but nothing changed: once the plugin is activated, I get the 404 error.

I can eventually post all the code, but I noticed many posts where the relevant part is the following:

function add_DeltaDocuments_custom_post_type()

            $labels = $this->set_ui_labels('DeltaDocument', 'DeltaDocuments');

            register_post_type('docs', array(
                    'labels' => $labels,
                    'public' => true,
                    'has_archive' => true,
                    'menu_icon' => 'dashicons-text-page',
                    'exclude_from_search' => false,
                    'taxonomies' => ['category'],
                    'rewrite' => array('slug' => 'docs'),
                    'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'revisions'),

Any help is appreciated.

  • Why does the first line unregister the post type that you're registering? This isn't necessary.
    – vancoder
    Commented Oct 5, 2022 at 17:46
  • @vancoder I coded this plugin only for personal purposes long time ago. Maybe I red it in some book as a good practice. Commented Oct 6, 2022 at 15:00

1 Answer 1


I solved by eliminating the following portion of code: I don't remember why I had to code it, it apparently solved an issue, even if I don't remember what issue.

The portion is the following:

add_action('pre_get_posts', function ($query) {
                if (!is_admin() && $query->is_main_query() && empty($query->query_vars['suppress_filters'])) {

        if (is_archive()) {

            if (is_category()) {
                $query->set('post_type', ['post', 'docs']);
            } else {
                if (!is_tag()) {
                    $query->set('post_type', 'docs');
                } else {
                    $query->set('post_type', 'post');

Maybe a newer version of WordPress had compatibility issues with this code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.