1

I am building a directory website which has various Custom post Types like Tours, Food, etc. The client would like to see landing Pages for each of the categories which can be edited manually (think archive page as a page template).

There is one taxonomy that needs to be assigned to each of the CPT's which is location. The location consists of a state term and its city child. E.g.:

Custom Taxonomy "Location":

-New South Wales

--Sydney

What I want to achieve is the following structure:


domain.com/food

A landing page create via a page with a page template


domain.com/food/New-South-Wales

A landing page create via a page with a page template. This is created with the food page as a parent


domain.com/food/New-South-Wales/Sydney

A landing page create via a page with a page template. This is created as a grandchild page with the food page as a grandparent and the News South Wales page as a parent


domain.com/food/New-South-Wales/Sydney/RestaurantX

This is the custom post type food single page, utilizing the location taxonomy to create the url structure.


At the moment I have the taxonomy and the CTPs setup without archive and using the CPT Permalinks plugin I am able to achieve all of the functionality, except of

domain.com/food/New-South-Wales/Sydney

which gives me a Page not found error.

Ideally I'd like to drop the CPT Permalinks plugin and create the structure by myself. Can anyone help me with this?

Thanks, Daniel

CPT Code

add_action( 'init', 'cptui_register_my_cpts' );
function cptui_register_my_cpts() {
$labels = array(
    "name" => "Foods",
    "singular_name" => "Food",
    );

$args = array(
    "labels" => $labels,
    "description" => "",
    "public" => true,
    "show_ui" => true,
    "has_archive" => false,
    "show_in_menu" => true,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
    "rewrite" => array( "slug" => "food", "with_front" => false ),
    "query_var" => true,
                    "supports" => array( "title", "editor", "excerpt", "thumbnail" ),           );
register_post_type( "food", $args );

$labels = array(
    "name" => "Bus Tours",
    "singular_name" => "Bus Tour",
    );

$args = array(
    "labels" => $labels,
    "description" => "",
    "public" => true,
    "show_ui" => true,
    "has_archive" => true,
    "show_in_menu" => true,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => false,
    "rewrite" => array( "slug" => "bus-tours", "with_front" => false ),
    "query_var" => true,
                    "supports" => array( "title", "editor", "excerpt", "thumbnail" ),           );
register_post_type( "bus-tours", $args );

// End of cptui_register_my_cpts()
}

Taxonomy Code:

add_action( 'init', 'cptui_register_my_taxes' );
function cptui_register_my_taxes() {

$labels = array(
    "name" => "location",
    "label" => "Locations",
        );

$args = array(
    "labels" => $labels,
    "hierarchical" => true,
    "label" => "Locations",
    "show_ui" => true,
    "query_var" => false,
    "rewrite" => array( 'slug' => 'location', 'with_front' => false  'hierarchical' => true ),
    "show_admin_column" => false,
);
register_taxonomy( "location", array( "food", "bus-tours" ), $args );

// End cptui_register_my_taxes
}
  • Hi Daniel, could you provide more details on what you've tried already (and why it didn't work)? Ideally including some code. – kraftner May 21 '15 at 8:56
  • Thanks for your help! At the moment I created the taxonomy and CPT's using the CPTUI Plugin (wordpress.org/plugins/custom-post-type-ui) I want to do this manually but since I am just trying a proof of concept I thought this would be quicker. – Daniel Klose May 21 '15 at 12:06
  • @kraftner I added the code used by the plugin to register the CPTs and Taxonomies. – Daniel Klose May 21 '15 at 13:34
  • Check out this very similar question: wordpress.stackexchange.com/questions/252450/… – Sam Jan 19 '17 at 1:18

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.