NO BUG: Template not showing for custom post type

Browser: Chrome 110
OS: macOS / Windows / Linux / etc.
URL: Link to a page that illustrates this issue
Video: Short screen recording that illustrates this issue (free tool: jam.dev)

Hello I am having a really bad time trying to make a template for a custom post type archive page and also for its single posts showing in the front-end. I am correctly viewing in when logged in but it is not working for logged out users.

The CPT is made with ACF and it’s public, publicly querable, and is an archive with the slug “esperienze”.

I correctly set the conditions both for the archive page as:
Archive > Post Type > Esperienza (name of the post type)

and for the single as:
Post type > Esperienza

I checked every settings, nothing is working. I correctly see it when logged in and editing the website but I does not work for logged-out users.

I also tried to disable every plugin to check if it was conflicting, nothing. Please help me.

Also this is the only CPT archive I have.

Fortunately (after hours of digging) I found that the problem was with a php snippet I was using to disable WordPress Posts:

<?php

// Hide "Posts" completely from frontend and backend
// ! This cause serious problem with Bricks Builder Templates
// add_action('pre_get_posts', function ($query) {
//     // Hide from all public queries
//     if (!is_admin() && $query->is_main_query() && !current_user_can('manage_options')) {
//         $query->set('post_type', ['page']); // Only show pages, for example
//     }
// });

add_action('admin_menu', function () {
    // Remove the "Posts" menu
    remove_menu_page('edit.php');
});

add_action('admin_bar_menu', function ($wp_admin_bar) {
    // Remove "New Post" from admin bar
    $wp_admin_bar->remove_node('new-post');
}, 999);

add_action('wp_dashboard_setup', function () {
    // Remove Quick Draft (which links to posts)
    remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
    remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
});

The first part was causing the problem, posting here for anynone having the same problems: always check your snippets :sad_but_relieved_face:

1 Like

Hi @OPStudio ,
Welcome to the forum!

I’m glad you’ve already tracked down the culprit :slight_smile: