пользовательская структура постоянных ссылок WordPress не изменена для всех пользовательских типов записей - PullRequest
0 голосов
/ 10 мая 2018

Я изменил структуру постоянных ссылок по умолчанию на моем сайте WordPress на: www.example.com/blog/%postname%/. Я хочу, чтобы часть '/ blog /' применялась только к сообщениям. У меня есть пользовательские типы записей, такие как «образование», «тематическое исследование» и «ресурс», где я не хочу, чтобы «блог» был частью URL. Я добавил аргумент rewrite в функцию register_post_type следующим образом: 'rewrite' => array('slug' => $slug , 'with_front' => false). Это работало для всех пользовательских типов постов, кроме «ресурса». Я добавил код для очистки правил перезаписи и сбросил постоянные ссылки без какого-либо успеха. Что-то мне не хватает?

РЕШЕНИЕ (ОБНОВЛЕНО): Вот код, где я регистрирую свои типы сообщений:

/** Remove extraneous resource custom post type */
add_action('init','delete_post_type', 5);
function delete_post_type(){
  unregister_post_type( 'resource' );
}

/** Register custom post types */
add_action( 'init', 'add_custom_register_post_types', 99 );
function add_custom_register_post_types() {    
  custom_register_post_type( 'Resource', 'Resources', 'resource', 'resources', true, array( 'title', 'editor', 'thumbnail' ), true, array( 'category' ) );
  custom_register_post_type( 'Case Study', 'Case Studies', 'case_study', 'case-studies', true, array( 'title', 'editor', 'thumbnail', ), true, array( 'category', 'post_tag' ) );
  custom_register_post_type( 'Product', 'Products', 'product', 'product', true, array( 'title', 'thumbnail' ), true, array(), false );
  custom_register_post_type( 'Guest Speaker', 'Guest Speakers', 'guest-speaker', 'guest-speaker', false, array( 'title', 'editor', 'thumbnail' ), true, array(), false );
  custom_register_post_type( 'News and Media Post', 'News and Media', 'news-and-media', 'company/news-and-media', true, array( 'title', 'editor' ), true, array() );
  custom_register_post_type( 'Education', 'Education', 'education', 'education1', true, array( 'title', 'editor', 'thumbnail', 'custom-fields' ), true, array( 'category', 'post_tag' ) );

  //flush_rewrite_rules();
}

function custom_register_post_type( $type, $types, $cpt_name, $slug, $search=false, $supports, $showui=true, $taxonomies, $has_archive = true ){

  $type2=strtolower( $type );
  $types2=strtolower( $types );

  $labels = array(
    'name' => $type,
    'singular_name' => $type,
    'add_new' => 'Add New',
    'add_new_item' => 'Add New ' .$type,
    'edit_item' => 'Edit '.$type,
    'new_item' => 'New '.$type,
    'view_item' => 'View '.$type,
    'search_items' => 'Search '.$types,
    'not_found' =>  'No '.$types2.' found',
    'not_found_in_trash' => 'No '.$types2.' found in Trash',
    'parent_item_colon' => '',
    'menu_name' => $types
  );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => $showui,
        'query_var' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'has_archive' => $has_archive,
        'rewrite' => array('slug' => $slug , 'with_front' => false),
        'exclude_from_search' => ! $search,
        'supports' => $supports,
        'taxonomies' => $taxonomies
    );

  register_post_type( $cpt_name, $args );
}

1 Ответ

0 голосов
/ 17 мая 2018

Я не смог выяснить, где в другом месте регистрировался пользовательский тип записи ресурса, но я нашел взлом, который решил мою проблему.Я добавил функцию отмены регистрации и установил приоритет действия выше, чем функция регистрации.Я обновил свой код, чтобы отразить решение.Я знаю, что это не лучшая практика, но я не хотел тратить вечно на попытки выяснить, где в другом месте кода создавался пользовательский тип публикации ресурса.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...