0

I created a custom post type using the CPT UI plugin and chose to add Categories as well. In my menu structure I have a second level item which is a category and a third level item which is the actual record or page the user should go to. On the front end the path looks like:

mysite.com/accommodation/theplace

There is no mention of the category in this url(not sure if that is a problem)

I have tried using single.php, archive.php, archive-accommodation.php and single-accommodation.php and putting some content onto all of those pages. However, it keeps going back to the home page.

function cptui_register_my_cpts_accommodation() {

    /**
     * Post Type: Accommodation.
     */

    $labels = array(
        "name" => __( "Accommodation", "mySite" ),
        "singular_name" => __( "Accommodation", "mySite" ),
        "menu_name" => __( "Accommodation", "mySite" ),
    );

    $args = array(
        "label" => __( "Accommodation", "mySite" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => false,
        "show_ui" => true,
        "show_in_rest" => false,
        "rest_base" => "",
        "has_archive" => false,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "exclude_from_search" => true,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => false,
        "rewrite" => array( "slug" => "accommodation", "with_front" => true ),
        "query_var" => true,
        "menu_icon" => "dashicons-store",
        "supports" => array( "title", "editor", "custom-fields", "page-attributes", "post-formats" ),
        "taxonomies" => array( "category" ),
    );

    register_post_type( "accommodation", $args );
}

add_action( 'init', 'cptui_register_my_cpts_accommodation' );
  • What is the custom post type named? (It might be accommodation, but it might also be {some_prefix_}accommodation.) – Pat J Apr 25 '18 at 18:32
  • @PatJ, I have updated the original question with the code – user8463989 Apr 25 '18 at 18:35
  • Well, according to the Template Hierarchy, you should be able to use single-accommodation.php for the single post and archive-accommodation.php for the post type archive. Have you tried re-saving your permalinks? – Pat J Apr 25 '18 at 19:06
  • Yeah, I would have thought so but it isn't working. I tried the re-saving of permalinks but still doesn't work – user8463989 Apr 25 '18 at 19:17
  • 2
    You have has_archive set to false, which means there won't be an archive for that post type. If you do want one, try unregister_post_type() to clear it out first, then re-register with has_archive set to true. Your slug/rewrite scenario shouldn't cause any problems using single-accommodation.php so I would double-check spelling (maybe you left out a C or M in the PHP template) and clear site cache, then check functions.php to make sure nothing weird like a template_include is going on. – WebElaine Apr 25 '18 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.