Второй пользовательский тип сообщения не отображается на веб-интерфейсе - PullRequest
0 голосов
/ 09 июля 2019

Код пост-типа для WP работает и отображается на веб-интерфейсе. Но когда он дублируется и заменяет «коллаборации» на «фильмы», он работает на стороне администратора, но возвращает 404 на внешнем интерфейсе.

Я удалил коды "movie" и попробовал несколько примеров, найденных в сети, и та же проблема все еще существует. Это работает для 1 типа сообщения, но не более 1. Любая причина, почему?

Код «совместной работы» идет по адресу «www.website.com/collaborations», что является правильным, а вторая - вместо «www.website.com/movies/movies/». Я добавил коды "кино" ниже.

Коды сотрудничества

function create_collaborations()
{
    register_post_type('collaborations',
        array('labels' => array('name' => __('collaborations'),'singular_name' => __('Collaborations')),'public' => true,'has_archive' => false,'rewrite' => array('slug' => 'collaborations'))
    );
}
add_action('init','create_collaborations');

function cw_post_type_collaborations()
{
    $supports = array('title', 'editor', 'thumbnail', 'revisions');

    $labels = array(
        'name'          => _x('Collaborations', 'plural'),
        'singular_name' => _x('Collaborations', 'singular'),
        'menu_name'     => _x('Collaborations', 'admin menu'),
        'name_admin_bar'=> _x('Collaborations', 'admin bar'),
        'add_new'       => _x('Add New', 'add new'),
        'add_new_item'  => __('Add New Collaborations'),
        'new_item'      => __('New Collaborations'),
        'edit_item'     => __('Edit Collaborations'),
        'view_item'     => __('View Collaborations'),
        'all_items'     => __('View Collaborations'),
        'search_items'  => __('Search Collaborations'),
        'not_found'     => __('No Collaborations found.')
    );

    $args = array(
        'supports'      => $supports,
        'labels'        => $labels,
        'public'        => true,
        'query_var'     => true,
        'rewrite'       => array('slug' => 'collaborations'),
        'has_archive'   => true,
        'hierarchical'  => false
    );

    register_post_type('collaborations', $args);
}
add_action('init', 'cw_post_type_collaborations');

Коды фильмов

function create_movies()
{
    register_post_type('movies',
        array('labels' => array('name' => __('movies'),'singular_name' => __('Movies')),'public' => true,'has_archive' => false,'rewrite' => array('slug' => 'movies'))
    );
}
add_action('init','create_movies');

function cw_post_type_movies()
{
    $supports = array('title', 'editor', 'thumbnail', 'revisions');

    $labels = array(
        'name'          => _x('Movies', 'plural'),
        'singular_name' => _x('Movies', 'singular'),
        'menu_name'     => _x('Movies', 'admin menu'),
        'name_admin_bar'=> _x('Movies', 'admin bar'),
        'add_new'       => _x('Add New', 'add new'),
        'add_new_item'  => __('Add New Movies'),
        'new_item'      => __('New Movies'),
        'edit_item'     => __('Edit Movies'),
        'view_item'     => __('View Movies'),
        'all_items'     => __('View Movies'),
        'search_items'  => __('Search Movies'),
        'not_found'     => __('No Movies found.')
    );

    $args = array(
        'supports'      => $supports,
        'labels'        => $labels,
        'public'        => true,
        'query_var'     => true,
        'rewrite'       => array('slug' => 'movies'),
        'has_archive'   => true,
        'hierarchical'  => false
    );

    register_post_type('movies', $args);
}
add_action('init', 'cw_post_type_movies');

1 Ответ

0 голосов
/ 09 июля 2019

Почему вы делаете один и тот же пост-тип два раза?

Возможно, я ошибаюсь, но я думаю, что вам нужны только вторые функции.

1.) function cw_post_type_movies() 
2.) function cw_post_type_collaborations()

Для фильмов просто используйте:

function cw_post_type_movies(){
$supports = array('title', 'editor', 'thumbnail', 'revisions');

$labels = array(
    'name'          => _x('Movies', 'plural'),
    'singular_name' => _x('Movies', 'singular'),
    'menu_name'     => _x('Movies', 'admin menu'),
    'name_admin_bar'=> _x('Movies', 'admin bar'),
    'add_new'       => _x('Add New', 'add new'),
    'add_new_item'  => __('Add New Movies'),
    'new_item'      => __('New Movies'),
    'edit_item'     => __('Edit Movies'),
    'view_item'     => __('View Movies'),
    'all_items'     => __('View Movies'),
    'search_items'  => __('Search Movies'),
    'not_found'     => __('No Movies found.')
);

$args = array(
    'supports'      => $supports,
    'labels'        => $labels,
    'public'        => true,
    'query_var'     => true,
    'rewrite'       => array('slug' => 'movies'),
    'has_archive'   => true,
    'hierarchical'  => false
);

register_post_type('movies', $args);
}
add_action('init', 'cw_post_type_movies');

Для совместной работы используйте:

function cw_post_type_collaborations(){
$supports = array('title', 'editor', 'thumbnail', 'revisions');

$labels = array(
    'name'          => _x('Collaborations', 'plural'),
    'singular_name' => _x('Collaborations', 'singular'),
    'menu_name'     => _x('Collaborations', 'admin menu'),
    'name_admin_bar'=> _x('Collaborations', 'admin bar'),
    'add_new'       => _x('Add New', 'add new'),
    'add_new_item'  => __('Add New Collaborations'),
    'new_item'      => __('New Collaborations'),
    'edit_item'     => __('Edit Collaborations'),
    'view_item'     => __('View Collaborations'),
    'all_items'     => __('View Collaborations'),
    'search_items'  => __('Search Collaborations'),
    'not_found'     => __('No Collaborations found.')
);

$args = array(
    'supports'      => $supports,
    'labels'        => $labels,
    'public'        => true,
    'query_var'     => true,
    'rewrite'       => array('slug' => 'collaborations'),
    'has_archive'   => true,
    'hierarchical'  => false
);

register_post_type('collaborations', $args);
}
add_action('init', 'cw_post_type_collaborations'); 

После создания обоих пользовательских типов записей перейдите к:

ваш-домен / сор-админ

Настройки> Постоянные ссылки> Сохранить изменения

=> Постоянные ссылки сбрасываются

...