Answer the question
In order to leave comments, you need to log in
How to display category slug in custom post url?
I have several custom post types, they all belong to some kind of headings (standard headings). In the CNC settings it is /%category%/%postname%/ , but the url of the entry looks like site.ru/post-type/post/ , and I need it to be like this site.ru/category-one/category-two/post / . How can I make the url look like this? For normal records everything works fine, but for custom records it doesn't. I’ll clarify right away that I’m not strong in programming, so I ask you to explain as simply as possible. And I’ll also clarify that there can be several nested categories and all of them should be reflected in the url.
Answer the question
In order to leave comments, you need to log in
To begin with, I would like to clarify exactly how you created the custom post type. If this was done in the "standard" way (by adding code via functions.php), then in the specified file you will find something like this:
register_post_type('fact', 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-format-quote',
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'supports' => array('title','author'),
'taxonomies' => array('factcat'),
'has_archive' => true,
'rewrite' => array('slug' => 'facts', 'with_front' => false),
'query_var' => true,
) );
'with_front' => falsechange to
'with_front' => true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question