0

I created custom post type named "Bikes" and four categories (Road, Scooter , Offroad and ATV) and each category have subcategories which I can use to assign custom post entries to.

So when I viewed the custom post entry and checked the url structure of it.

domainname/bikes/post-name-sample

What are the correct method if I put the post entry to category or subcategory:

domainname/bikes/road/post-name-sample

or if the post entry is in subcategory

domainname/bikes/road/superbike/post-name-sample

This is what I have currently modified but need help to how can I get the category and subcategory to work for custom post type.

/**
     * Post Type: Products.
     */

    $labels = array(
        "name" => __( "Products", "twentytwo" ),
        "singular_name" => __( "Products", "twentytwo" ),
    );

    $args = array(
        "label" => __( "Products", "twentytwo" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "delete_with_user" => false,
        "show_in_rest" => true,
        "rest_base" => "",
        "rest_controller_class" => "WP_REST_Posts_Controller",
        "has_archive" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => true,
        "rewrite" => array( "slug" => "products", "with_front" => true ),
        "query_var" => true,
        "supports" => array( "title", "editor", "thumbnail" ),
        "taxonomies" => array( "motorcycles_type" ),
    );

    register_post_type( "products", $args );
}

add_action( 'init', 'cptui_register_my_cpts' );

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.