Answer the question
In order to leave comments, you need to log in
How to create custom categories in wordpress and put custom post types in them?
The task is as follows:
Create 3 custom categories: Moscow, Chekhov, Zvenigorod
Create 2 new types of records (maybe 6, 2 in each city): Services, Specialists
Place the created types in each of the cities.
so that the structure is as follows
/moskva/uslugi/ - an archive with all services
/moskva/uslugi/oformlenie-medknizhek/ - a separate service page
/moskva/specialisti/hirurg/ - a separate specialist page
/chehov/specialisti/psihiatr/ - a separate specialist page
. ..
The screenshot may be clearer.
I tried to do it through custom taxonomies, I thought it works like categories, but I get some kind of tags.
Please tell me the best way to do this.
Answer the question
In order to leave comments, you need to log in
Hello!
I will not write all the code...
I will tell you the main points that you should consider
1) Registering a taxonomy and a custom post type
add_action('init', 'register_post_types');
function register_post_types(){
register_taxonomy('objectcat', array('object'), array(
'label' => 'Рубрики объектов',
'labels' => array(
'name' => 'Рубрики объектов',
'singular_name' => 'Рубрики объектов',
'search_items' => 'Искать рубрики',
'all_items' => 'Все рубрики',
'parent_item' => 'Родит. рубрика',
'parent_item_colon' => 'Родит. рубрика:',
'edit_item' => 'Редактировать рубрику',
'update_item' => 'Обновить рубрику',
'add_new_item' => 'Добавить рубрику',
'new_item_name' => 'Заголовок',
'menu_name' => 'Рубрики объектов',
),
'description' => 'Рубрики для объектов',
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'hierarchical' => true ),
'show_admin_column' => true,
) );
// Объекты
register_post_type('object', array(
'label' => 'Объект',
'labels' => array(
'name' => 'Объекты',
'singular_name' => 'Объект',
'add_new' => 'Добавить новый',
'add_new_item' => 'Введите заголовок',
'edit_item' => 'Редактирование объекта',
'new_item' => 'Новый объект',
'view_item' => 'Посмотреть объект',
'search_items' => 'Искать объект',
'not_found' => 'Объектов не найдено',
'not_found_in_trash' => 'В корзине объектов не найдено',
'parent_item_colon' => '',
'menu_name' => 'Объекты',
),
'description' => 'Объекты',
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 23,
'menu_icon' => 'dashicons-plus-alt',
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'supports' => array('title','thumbnail'),
'taxonomies' => array('objectcat', 'localcat'),
'has_archive' => true,
'rewrite' => array('slug' => 'objects', 'with_front' => false),
'query_var' => true,
) );
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question