Support » Networking WordPress » CPT Archive page > 404 since turning on MU

  • Resolved SRD75

    (@srd75)


    We have a custom post type called Locations.

    Since turning on subdirectory MU, the locations’ URLs have changed from:

    https://mandoemedia.com/locations/jacksonville/

    to

    https://mandoemedia.com/blog/locations/jacksonville/

    This is okay in theory.

    However, the Locations archive page is now producing a 404 page.

    ie. Both https://mandoemedia.com/locations/ & https://mandoemedia.com/blog/locations/ produce a 404.

    Our Yoast SEO sitemap for Locations contains the URL https://mandoemedia.com/blog/locations/ as if that is the correct URL, but that is producing the 404.

    In our CPT definition, we have:

    function create_locations() {
    
    	$labels = array(
    		'name' => _x( 'Locations', 'Post Type General Name', 'textdomain' ),
    		'singular_name' => _x( 'Locations', 'Post Type Singular Name', 'textdomain' ),
    		'menu_name' => _x( 'Locations', 'Admin Menu text', 'textdomain' ),
    		'name_admin_bar' => _x( 'Locations', 'Add New on Toolbar', 'textdomain' ),
    		'archives' => __( 'Locations Archives', 'textdomain' ),
    		'attributes' => __( 'Locations Attributes', 'textdomain' ),
    		'parent_item_colon' => __( 'Parent Locations:', 'textdomain' ),
    		'all_items' => __( 'All Locations', 'textdomain' ),
    		'add_new_item' => __( 'Add New Locations', 'textdomain' ),
    		'add_new' => __( 'Add New', 'textdomain' ),
    		'new_item' => __( 'New Locations', 'textdomain' ),
    		'edit_item' => __( 'Edit Locations', 'textdomain' ),
    		'update_item' => __( 'Update Locations', 'textdomain' ),
    		'view_item' => __( 'View Locations', 'textdomain' ),
    		'view_items' => __( 'View Locations', 'textdomain' ),
    		'search_items' => __( 'Search Locations', 'textdomain' ),
    		'not_found' => __( 'Not found', 'textdomain' ),
    		'not_found_in_trash' => __( 'Not found in Trash', 'textdomain' ),
    		'featured_image' => __( 'Featured Image', 'textdomain' ),
    		'set_featured_image' => __( 'Set featured image', 'textdomain' ),
    		'remove_featured_image' => __( 'Remove featured image', 'textdomain' ),
    		'use_featured_image' => __( 'Use as featured image', 'textdomain' ),
    		'insert_into_item' => __( 'Insert into Locations', 'textdomain' ),
    		'uploaded_to_this_item' => __( 'Uploaded to this Locations', 'textdomain' ),
    		'items_list' => __( 'Locations list', 'textdomain' ),
    		'items_list_navigation' => __( 'Locations list navigation', 'textdomain' ),
    		'filter_items_list' => __( 'Filter Locations list', 'textdomain' ),
    	);
    	$args = array(
    		'label' => __( 'Locations', 'textdomain' ),
    		'description' => __( '', 'textdomain' ),
    		'labels' => $labels,
    		'menu_icon' => 'dashicons-location-alt',
    		'supports' => array('title', 'excerpt', 'thumbnail', 'page-attributes', 'post-formats'),
    		'taxonomies' => array(),
    		'public' => true,
    		'show_ui' => true,
    		'show_in_menu' => true,
    		'menu_position' => 5,
    		'show_in_admin_bar' => true,
    		'show_in_nav_menus' => true,
    		'can_export' => true,
    		'has_archive' => true,
    		'hierarchical' => false,
    		'exclude_from_search' => false,
    		'show_in_rest' => true,
    		'publicly_queryable' => true,
    		'capability_type' => 'post',
    	);
    	register_post_type( 'locations', $args );

    Note: 'has_archive' => true,.

    Other pages & posts are displaying fine.

    Help appreciated.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Your MU is presumably the subfolder kind, so inserting the site’s subfolder name into all URLs would make sense. I agree with Yoast that the /blog/locations/ is the correct URL. In theory.

    So the question becomes why do we get a 404 with a “correct” URL? It’s because the query WP is using fails to return anything. If you examine the SQL actually used, it’s often a good clue to what’s going wrong. The Query Monitor plugin is an easy way to examine SQL queries. Make the request, yielding a 404. Click the query data in the admin bar. Go to the plugin’s queries section. Filter the list by caller Main Query.

    If SQL isn’t your forte and it’s unclear why the query has a problem, post it here and perhaps I or someone else will be able to make more sense of it.

    Thread Starter SRD75

    (@srd75)

    Hi @bcworkz

    @tw2113 solved the problem for me:

    The article https://wordpress.stackexchange.com/questions/107901/remove-the-blog-slug-from-wordpress-multisite-root-node contained the solution (removing blog from the network > main site > settings > permalinks).

    Thank you for responding!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.