• Hey guys,

    I have a wordpress network with 9 websites, all with the same configuration and same custom post types.

    Every website has more custom post types but only 2 gave me the 404 error: restaurant and camera(room).

    This is the 2 custom post types declaration:

    $labels = array(
        'name' => _x('Restaurante', 'restaurant'),
        'singular_name' => _x('Restaurant', 'restaurant'),
        'add_new' => _x('Adauga Restaurant', 'restaurant'),
        'add_new_item' => __('Adauga Restaurant'),
        'edit_item' => __('Editeaza Restaurant'),
        'new_item' => __('Restaurant Nou'),
        'view_item' => __('Vizualizeaza Restaurant'),
        'search_items' => __('Cauta Restaurant'),
        'not_found' =>  __('Nu s-a gasit niciun Restaurant'),
        'not_found_in_trash' => __('Niciun Restaurant in Trash'),
        'parent_item_colon' => ''
      );
    register_post_type('restaurant', array(
    	'label' => __('Restaurante'),
    	'labels' => $labels,
    	'singular_label' => __('Restaurant'),
    	'public' => true,
    	'show_ui' => true,
    	'capability_type' => 'post',
    	'add_new' => _x('Restaurant Nou', 'restaurant'),
    	'add_new_item' => __('Restaurant Nou'),
    	'rewrite' => array( 'slug' => 'restaurant-hotel', 'with_front' => false ),
    	'query_var' =>false,
    	'menu_position' => 7,
    	'hierarchical' => true,
    	'supports' => array('title', 'editor', 'thumbnail', 'page-attributes')
    ));
    $labels = array(
        'name' => _x('Camere', 'camera'),
        'singular_name' => _x('Camera', 'camera'),
        'add_new' => _x('Adauga Camera', 'camera'),
        'add_new_item' => __('Adauga Camera'),
        'edit_item' => __('Editeaza Camera'),
        'new_item' => __('Camera Noua'),
        'view_item' => __('Vizualizeaza Camera'),
        'search_items' => __('Cauta Camera'),
        'not_found' =>  __('Nu s-a gasit nicio Camera'),
        'not_found_in_trash' => __('Nicio Camera in Trash'),
        'parent_item_colon' => ''
      );
    register_post_type('camera', array(
    	'label' => __('Camere'),
    	'labels' => $labels,
    	'singular_label' => __('Camera'),
    	'public' => true,
    	'show_ui' => true,
    	'capability_type' => 'post',
    	'add_new' => _x('Camera Noua', 'camera'),
    	'add_new_item' => __('Camera Noua'),
    	'hierarchical' => false,
    	'rewrite' => array( 'slug' => 'room', 'with_front' => false ),
    	'query_var' => false,
    	'menu_position' => 7,
    	'register_meta_box_cb' => 'ch_camera_metaboxes',
    	'supports' => array('title', 'editor', 'thumbnail')
    ));

    If i reset the permalinks structure all this works, but only for a while.
    I deactivated all the plugin, same story.
    Also, i have no page with the custom post type slug as a name.

    What i don’t understand is why this happens only for this 2, and not for all custom post types active on the website and what trigger this error.

    This is how WP_Query and WP_rewrite looks like when the 404 error is triggered. Note that wordpress searches for an attachment instead of that specific custom post type:

    When “camera” post type fails – https://pastebin.com/nZzsxK4V (WP_Query) and https://pastebin.com/3bDp2aF4 (WP_Rewrite)

    When “restaurant” post type fails – https://pastebin.com/3wnzP8uL

    The url for this website is https://continentalhotels.ro/Grand-Hotel-Continental-Bucuresti/ and the links for 404 are: https://continentalhotels.ro/Grand-Hotel-Continental-Bucuresti/room/camera-superior/ for “camera” custom post type and https://continentalhotels.ro/Grand-Hotel-Continental-Bucuresti/restaurant-hotel/concerto/ for “restaurant” custom post type.

    Note that in the moment you access the url they could work since i’ve added a cron for flushing the rewrite rules hourly until i fix this.

    Any help is highly appreciated!
    Thanks.

  • The topic ‘404 for custom post types’ is closed to new replies.