V
V
VitaliyBorys2018-09-05 14:18:18
WordPress
VitaliyBorys, 2018-09-05 14:18:18

How to setup Permalink custom post types?

Hello everyone )) Guys, there is a page on Wordpress, the link to it looks like this:
mysite.com/learn/books
I created my post type ( register_post_type() ) - "book". Do I need a link to one book to look like this ? :
mysite.com/learn/books/book-name
Tell me how to do it?
If you specify when registering your post type: 'rewrite' => ['slug' => 'learn/books', 'with_front' => false]
Links to one book will be correct, but this page is mysite.com/learn/books
will have post_type also book, but should be page !

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
campusboy, 2018-09-05
@VitaliyBorys

Hello. Strange, I'm fine. Added code:

add_action( 'init', 'my_custom_init' );
function my_custom_init() {
    register_post_type( 'book', [
        'labels'   => [
            'name'               => 'Книги', // Основное название типа записи
            'singular_name'      => 'Книга', // отдельное название записи типа Book
            'add_new'            => 'Добавить новую',
            'add_new_item'       => 'Добавить новую книгу',
            'edit_item'          => 'Редактировать книгу',
            'new_item'           => 'Новая книга',
            'view_item'          => 'Посмотреть книгу',
            'search_items'       => 'Найти книгу',
            'not_found'          => 'Книг не найдено',
            'not_found_in_trash' => 'В корзине книг не найдено',
            'menu_name'          => 'Книги',

        ],
        'public'   => true,
        'rewrite'  => [ 'slug' => 'learn/books' ],
        'supports' => [ 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ],
    ] );
}

After adding the code, I reset the rewrites. I created the "Learning" page (slug = learn), then made the "All Books" page child to it (slug = books). Now, when accessing wp-test.ru/learn/books/moya-pervaya-kniga/, a record with post_type=book opens, and when accessing wp-test.ru/learn/books/, a page with post_type=page opens.
True, I did not really understand the desire to make an archive of the book record type in the form of a page. What is the purpose?

R
rubtsoff, 2018-09-05
@rubsoff

create taxonomy with them everything is much easier
Z2Ohv.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question