Benutzerdefinierte Post-Typ und Taxonomie-Permalinks – Struktur

Ich habe versucht, ein Nest von benutzerdefinierten Post-Typ und Taxonomie arbeiten (sah sogar hier ), aber konnte es nicht funktioniert 100%.

Hier ist die Sache, ich habe einen benutzerdefinierten Beitragstyp texturas_temp und eine benutzerdefinierte Taxonomie in ihm categorias_texturas_temp erstellt .

Ich möchte diese Struktur erhalten:

  • / texturas_temp / <- Zeigt alle kategorien_texturas_temp an
  • / texturas_temp / categorias_texturas_temp <- Zeigt alle texturas_temp mit diesem bestimmten categorias_texturas_temp Begriff an
  • / texturas_temp / categorias_texturas_temp / texturas_temp_post <- Zeigt einzelne texturas_temp an

Es ist ungefähr dasselbe wie ein Geschäft mit / products / category / product

Ich habe diesen Code zuerst zum Erstellen meiner benutzerdefinierten Taxonomie verwendet :

// texturas_temp - Categorias // ============================================================================= if ( ! function_exists( 'categorias_texturas_temp' ) ) { // Register Custom Taxonomy function taxonomy_categorias_texturas_temp() { $labels = array( 'name' => _x( 'Categorias de texturas_temp', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Categoria de texturas_temp', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Categoria de texturas_temp', 'text_domain' ), 'all_items' => __( 'Todos as categorias', 'text_domain' ), 'parent_item' => __( 'Categoria Pai', 'text_domain' ), 'parent_item_colon' => __( 'Categoria Pai:', 'text_domain' ), 'new_item_name' => __( 'Adicionar novo nome', 'text_domain' ), 'add_new_item' => __( 'Adicionar novo item', 'text_domain' ), 'edit_item' => __( 'Editar Categoria', 'text_domain' ), 'update_item' => __( 'Atualizar Categoria', 'text_domain' ), 'view_item' => __( 'Visualizar categoria', 'text_domain' ), 'separate_items_with_commas' => __( 'Separar itens com vírgulas', 'text_domain' ), 'add_or_remove_items' => __( 'Adicionar ou Remover Itens', 'text_domain' ), 'choose_from_most_used' => __( 'Escolher dos mais utilizados', 'text_domain' ), 'popular_items' => __( 'Itens Populares', 'text_domain' ), 'search_items' => __( 'Procurar Itens', 'text_domain' ), 'not_found' => __( 'Não Encontrado', 'text_domain' ), 'items_list' => __( 'Lista de Itens', 'text_domain' ), 'items_list_navigation' => __( 'Navegação Lista de Itens', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'rewrite' => array( 'slug' => 'texturas_temp', // This controls the base slug that will display before each term ), 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy( 'categorias-texturas_temp', array( 'texturas_temp' ), $args ); } add_action( 'init', 'taxonomy_categorias_texturas_temp', 0 ); } 

Ich habe diesen Code zum Erstellen meiner Permalink-Kategorien verwendet : texturas_temp :

 // Modificar permalink add_filter('post_link', 'brand_permalink', 1, 3); add_filter('post_type_link', 'brand_permalink', 1, 3); function brand_permalink($permalink, $post_id, $leavename) { //con %categorias_texturas_temp% catturo il rewrite del Custom Post Type if (strpos($permalink, '%categorias-texturas_temp%') === FALSE) return $permalink; // Get post $post = get_post($post_id); if (!$post) return $permalink; // Get taxonomy terms $terms = wp_get_object_terms($post->ID, 'categorias-texturas_temp'); if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug; else $taxonomy_slug = 'no-categorias-texturas_temp'; return str_replace('%categorias-texturas_temp%', $taxonomy_slug, $permalink); } 

Und dann das für meinen benutzerdefinierten Posttyp :

 // texturas_temp // ============================================================================= if ( ! function_exists('texturas_temp') ) { // Register Custom Post Type function texturas_temp() { $labels = array( 'name' => _x( 'texturas_temp', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Textura', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'texturas_temp', 'text_domain' ), 'name_admin_bar' => __( 'texturas_temp', 'text_domain' ), 'parent_item_colon' => __( 'Textura:', 'text_domain' ), 'all_items' => __( 'Todas', 'text_domain' ), 'add_new_item' => __( 'Adicionar Nova Textura', 'text_domain' ), 'add_new' => __( 'Adicionar Nova', 'text_domain' ), 'new_item' => __( 'Adicionar Textura', 'text_domain' ), 'edit_item' => __( 'Editar Textura', 'text_domain' ), 'update_item' => __( 'Atualizar Textura', 'text_domain' ), 'view_item' => __( 'Visualizar Textura', 'text_domain' ), 'search_items' => __( 'Pesquisar Textura', 'text_domain' ), 'not_found' => __( 'Nenhuma Textura Encontrada', 'text_domain' ), 'not_found_in_trash' => __( 'Nenhuma Textura Econtrada no Lixo', 'text_domain' ), 'items_list' => __( 'Lista de texturas_temp', 'text_domain' ), 'items_list_navigation' => __( 'Navegação Lista de texturas_temp', 'text_domain' ), 'filter_items_list' => __( 'Filtras Lista de texturas_temp', 'text_domain' ), ); $args = array( 'label' => __( 'Textura', 'text_domain' ), 'description' => __( 'texturas_temp da Futon Company.', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ), 'taxonomies' => array( 'texturas_temp' ), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-tagcloud', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => true, 'hierarchical' => true, 'rewrite' => array( 'slug' => 'texturas_temp/%categorias-texturas_temp%', // This controls the base slug that will display before each term 'with_front' => false // Don't display the category base before "/locations/" ), 'query_var' => true, 'exclude_from_search' => false, 'capability_type' => 'page', ); register_post_type( 'texturas_temp', $args ); } add_action( 'init', 'texturas_temp', 0 ); } 

Was ich bekam:

  • / texturas_temp / <- 404 mit archive-texturas_temp.php Vorlage
  • / texturas_temp / categorias_texturas_temp <- Großartig mit taxonomy-categorias-texturas_temp.php- Vorlage
  • / texturas_temp / categorias_texturas_temp / texturas_temp_post <- Großartig mit single-texturas_temp.php Vorlage

Also im Grunde kann ich nicht scheinen, dass die Elternseite funktioniert, auch meine Breadcrumbs zeigt es nicht in der richtigen Weise (springt die Kategorie)

Mache ich alles falsch? Das ist meine Sorge …

Ich weiß, es wurde eine Million Male gefragt, verdammt, ich habe sogar alles aus dem Link, den ich gefunden habe, versucht.

Kann jemand etwas Licht geben?

Vielen Dank !

UPDATE: Ich habe den Inspektor der Plug-in- Rewrite-Regeln gerollt und habe keine Fehler darin:

 texturas_temp/%categorias-texturas_temp%/?$ index.php?post_type=texturas_temp other texturas_temp/%categorias-texturas_temp%/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?post_type=texturas_temp&feed=$matches[1] other texturas_temp/%categorias-texturas_temp%/(feed|rdf|rss|rss2|atom)/?$ index.php?post_type=texturas_temp&feed=$matches[1] other texturas_temp/%categorias-texturas_temp%/page/([0-9]{1,})/?$ index.php?post_type=texturas_temp&paged=$matches[1] other texturas_temp/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&feed=$matches[2] texturas_temp texturas_temp/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&feed=$matches[2] texturas_temp texturas_temp/([^/]+)/page/?([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&paged=$matches[2] texturas_temp texturas_temp/([^/]+)/?$ index.php?categorias-texturas_temp=$matches[1] texturas_temp texturas_temp/[^/]+/.+?/attachment/([^/]+)/?$ index.php?attachment=$matches[1] texturas_temp texturas_temp/[^/]+/.+?/attachment/([^/]+)/trackback/?$ index.php?attachment=$matches[1]&tb=1 texturas_temp texturas_temp/[^/]+/.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?attachment=$matches[1]&feed=$matches[2] texturas_temp texturas_temp/[^/]+/.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ index.php?attachment=$matches[1]&feed=$matches[2] texturas_temp texturas_temp/[^/]+/.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$ index.php?attachment=$matches[1]&cpage=$matches[2] texturas_temp texturas_temp/([^/]+)/(.+?)/trackback/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&tb=1 texturas_temp texturas_temp/([^/]+)/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&feed=$matches[3] texturas_temp texturas_temp/([^/]+)/(.+?)/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&feed=$matches[3] texturas_temp texturas_temp/([^/]+)/(.+?)/page/?([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&paged=$matches[3] texturas_temp texturas_temp/([^/]+)/(.+?)/comment-page-([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&cpage=$matches[3] texturas_temp texturas_temp/([^/]+)/(.+?)/cornerstone-endpoint(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&cornerstone-endpoint=$matches[4] texturas_temp texturas_temp/([^/]+)/(.+?)/wc-api(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&wc-api=$matches[4] texturas_temp texturas_temp/[^/]+/.+?/([^/]+)/cornerstone-endpoint(/(.*))?/?$ index.php?attachment=$matches[1]&cornerstone-endpoint=$matches[3] texturas_temp texturas_temp/[^/]+/.+?/attachment/([^/]+)/cornerstone-endpoint(/(.*))?/?$ index.php?attachment=$matches[1]&cornerstone-endpoint=$matches[3] texturas_temp texturas_temp/[^/]+/.+?/([^/]+)/wc-api(/(.*))?/?$ index.php?attachment=$matches[1]&wc-api=$matches[3] texturas_temp texturas_temp/[^/]+/.+?/attachment/([^/]+)/wc-api(/(.*))?/?$ index.php?attachment=$matches[1]&wc-api=$matches[3] texturas_temp texturas_temp/([^/]+)/(.+?)(/[0-9]+)?/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&page=$matches[3] texturas_temp texturas_temp/([^/]+)/comment-page-([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&cpage=$matches[2] texturas_temp texturas_temp/([^/]+)/cornerstone-endpoint(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&cornerstone-endpoint=$matches[3] texturas_temp texturas_temp/([^/]+)/wc-api(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&wc-api=$matches[3] texturas_temp 

Solutions Collecting From Web of "Benutzerdefinierte Post-Typ und Taxonomie-Permalinks – Struktur"

ERLEDIGT

Mein Problem war der Fehlercode im Array des benutzerdefinierten Post-Typs texturas_temp

Dies:

 // Register Custom Post Type function texturas_temp() { $labels = array( 'name' => _x( 'texturas_temp', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Textura', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'texturas_temp', 'text_domain' ), 'name_admin_bar' => __( 'texturas_temp', 'text_domain' ), 'parent_item_colon' => __( 'Textura:', 'text_domain' ), 'all_items' => __( 'Todas', 'text_domain' ), 'add_new_item' => __( 'Adicionar Nova Textura', 'text_domain' ), 'add_new' => __( 'Adicionar Nova', 'text_domain' ), 'new_item' => __( 'Adicionar Textura', 'text_domain' ), 'edit_item' => __( 'Editar Textura', 'text_domain' ), 'update_item' => __( 'Atualizar Textura', 'text_domain' ), 'view_item' => __( 'Visualizar Textura', 'text_domain' ), 'search_items' => __( 'Pesquisar Textura', 'text_domain' ), 'not_found' => __( 'Nenhuma Textura Encontrada', 'text_domain' ), 'not_found_in_trash' => __( 'Nenhuma Textura Econtrada no Lixo', 'text_domain' ), 'items_list' => __( 'Lista de texturas_temp', 'text_domain' ), 'items_list_navigation' => __( 'Navegação Lista de texturas_temp', 'text_domain' ), 'filter_items_list' => __( 'Filtras Lista de texturas_temp', 'text_domain' ), ); $args = array( 'label' => __( 'Textura', 'text_domain' ), 'description' => __( 'texturas_temp da Futon Company.', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ), 'taxonomies' => array( 'texturas_temp' ), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-tagcloud', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'hierarchical' => true, 'rewrite' => array( 'slug' => 'texturas_temp/%categorias-texturas_temp%', // This controls the base slug that will display before each term 'with_front' => false // Don't display the category base before "/locations/" ), 'query_var' => 'texturas_temp-term', 'exclude_from_search' => false, 'has_archive' => 'texturas_temp', 'capability_type' => 'page', ); register_post_type( 'texturas_temp', $args ); } add_action( 'init', 'texturas_temp', 0 ); } 

Zu diesem:

 // Register Custom Post Type function texturas_temp() { $labels = array( 'name' => _x( 'texturas_temp', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Textura', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'texturas_temp', 'text_domain' ), 'name_admin_bar' => __( 'texturas_temp', 'text_domain' ), 'parent_item_colon' => __( 'Textura:', 'text_domain' ), 'all_items' => __( 'Todas', 'text_domain' ), 'add_new_item' => __( 'Adicionar Nova Textura', 'text_domain' ), 'add_new' => __( 'Adicionar Nova', 'text_domain' ), 'new_item' => __( 'Adicionar Textura', 'text_domain' ), 'edit_item' => __( 'Editar Textura', 'text_domain' ), 'update_item' => __( 'Atualizar Textura', 'text_domain' ), 'view_item' => __( 'Visualizar Textura', 'text_domain' ), 'search_items' => __( 'Pesquisar Textura', 'text_domain' ), 'not_found' => __( 'Nenhuma Textura Encontrada', 'text_domain' ), 'not_found_in_trash' => __( 'Nenhuma Textura Econtrada no Lixo', 'text_domain' ), 'items_list' => __( 'Lista de texturas_temp', 'text_domain' ), 'items_list_navigation' => __( 'Navegação Lista de texturas_temp', 'text_domain' ), 'filter_items_list' => __( 'Filtras Lista de texturas_temp', 'text_domain' ), ); $args = array( 'label' => __( 'Textura', 'text_domain' ), 'description' => __( 'texturas_temp da Futon Company.', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', 'post-formats', ), 'taxonomies' => array( 'categorias-texturas_temp' ), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-tagcloud', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'hierarchical' => true, 'rewrite' => array( 'slug' => 'texturas_temp/%categorias-texturas_temp%', // This controls the base slug that will display before each term 'with_front' => false // Don't display the category base before "/locations/" ), 'query_var' => 'texturas_temp-term', 'exclude_from_search' => false, 'has_archive' => 'texturas_temp', 'capability_type' => 'page', ); register_post_type( 'texturas_temp', $args ); } add_action( 'init', 'texturas_temp', 0 ); } 

Im Grunde habe ich meinen benutzerdefinierten Post-Typ mit einer eigenen Taxonomie benannt, geändert:

 'taxonomies' => array( 'texturas_temp' ), 

Zu:

 'taxonomies' => array( 'categorias-texturas_temp' ), 

Gut in Ordnung …