Custom post type single page returns 404


Edit: this may offer an important clue. When I’m logged in as the admin, the links work fine, but when I’m logged out I get the 404 error.

Before posting I tried almost every suggestion from searching StackExchange and google.

Overview: When I enter the permalink of a post it returns a 404. When I click on a link created by get_the_permalink(); I will see a 404 and this url structure ?post_type=lunchlearn&p=530 rather than /lunchlearn/burner-start-up-and-tech/

I’ve tried saving the permalink structure, flush_rewrite_rules, different rewrite rules, etc. Any help would be extremely appreciated.

I have a few custom post types I created within the functions.php. One example is below:

function register_lunchandlearn () {
  // Lunch and Learn post type
  $labels = array(
        'name' => 'Lunch and Learn',
        'singular_name' => 'Lunch and Learn',
        'add_new' => 'Add Event',
        'all_items' => 'All Events',
        'add_new_item' => 'Add Event',
        'edit_item' => 'Edit Event',
        'new_item' => 'New Event',
        'view_item' => 'View Event',
        'search_item' => 'Search Events',
        'not_found' => 'No events found',
        'not_found_in_trash' => 'No events found in trash',
        'parent_item_colon' => 'Parent event'
    $args = array(
        'labels' => $labels,
        'menu_icon' => 'dashicons-welcome-learn-more',
        'public' => true,
        'has_archive' => true,
        'publicly_queryable' => true,
        'query_var' => true,
        'rewrite'               => array( 'slug' => 'lunchlearn', 'with_front' => false ),
        'capability_type' => 'post',
        'hierarchical' => false,
        'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions'),
        'taxonomies' => array('category', 'post_tag'),
        'menu_position' => 5,
        'exclude_from_search' => false,
cesjr02 4 years 2020-03-03T07:50:09-05:00 0 Answers 95 views 0

Leave an answer