Visite a página de permalinks (que irá liberá-la) e verifique novamente. O WordPress provavelmente só precisa ser estimulado para reconhecer sua adição à hierarquia.
Eu fiz um tipo de post personalizado com o nome da máquina special_media_post e o wordpress simplesmente não está vendo o single-special_media_post.php. Eu estou completamente perdido. Ele mantém o padrão para o index.php
Aqui está o meu código para o meu tipo de postagem personalizado e suas taxonomias:
//Post and Taxonomy stuff
//Register Custom Post Type
function special_media_post() {
$labels = array(
'name' => _x( 'Media Posts', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Media Post', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Media Post', 'text_domain' ),
'parent_item_colon' => __( 'Media Post:', 'text_domain' ),
'all_items' => __( 'All Media Posts', 'text_domain' ),
'view_item' => __( 'View Media Post', 'text_domain' ),
'add_new_item' => __( 'Add New Media Post', 'text_domain' ),
'add_new' => __( 'New Media Post', 'text_domain' ),
'edit_item' => __( 'Edit Media Post', 'text_domain' ),
'update_item' => __( 'Update Media Post', 'text_domain' ),
'search_items' => __( 'Search Media Posts', 'text_domain' ),
'not_found' => __( 'No media posts found', 'text_domain' ),
'not_found_in_trash' => __( 'No media posts found in Trash', 'text_domain' ),
);
$rewrite = array(
'slug' => 'mediapost',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'mediapost', 'text_domain' ),
'description' => __( 'Post Type for Media', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'custom-fields', ),
'taxonomies' => array( 'year', 'type' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'mediapost',
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'special_media_post', $args );
}
// Register Custom Taxonomy
function media_year() {
$labels = array(
'name' => _x( 'Years', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Year', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Year', 'text_domain' ),
'all_items' => __( 'All Years', 'text_domain' ),
'parent_item' => __( 'Parent Year', 'text_domain' ),
'parent_item_colon' => __( 'Parent Year:', 'text_domain' ),
'new_item_name' => __( 'New Year Name', 'text_domain' ),
'add_new_item' => __( 'Add New Year', 'text_domain' ),
'edit_item' => __( 'Edit Year', 'text_domain' ),
'update_item' => __( 'Update Year', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate years with commas', 'text_domain' ),
'search_items' => __( 'Search years', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove years', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used yearss', 'text_domain' ),
);
$rewrite = array(
'slug' => 'year',
'with_front' => true,
'hierarchical' => true,
);
$capabilities = array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => 'year',
'rewrite' => $rewrite,
'capabilities' => $capabilities,
);
register_taxonomy( 'year', 'special_media_post', $args );
}
// Register Custom Taxonomy
function media_type() {
$labels = array(
'name' => _x( 'Types', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Type', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Type', 'text_domain' ),
'all_items' => __( 'All Types', 'text_domain' ),
'parent_item' => __( 'Parent Type', 'text_domain' ),
'parent_item_colon' => __( 'Parent Type:', 'text_domain' ),
'new_item_name' => __( 'New Type Name', 'text_domain' ),
'add_new_item' => __( 'Add New Type', 'text_domain' ),
'edit_item' => __( 'Edit Type', 'text_domain' ),
'update_item' => __( 'Update Type', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate types with commas', 'text_domain' ),
'search_items' => __( 'Search types', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove types', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used types', 'text_domain' ),
);
$rewrite = array(
'slug' => 'type',
'with_front' => true,
'hierarchical' => true,
);
$capabilities = array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => 'media_type',
'rewrite' => $rewrite,
'capabilities' => $capabilities,
);
register_taxonomy( 'type', 'special_media_post', $args );
}
// Hook into the 'init' action
add_action( 'init', 'special_media_post', 0 );
// Hook into the 'init' action
add_action( 'init', 'media_year', 0 );
// Hook into the 'init' action
add_action( 'init', 'media_type', 0 );
Se houver algo mais que você precise ver, eu posso colocá-lo, mas ele nem vê se eu colocar um eco 'Hello World' lá. Então, simplesmente não está vendo o single-special_media_post.php ou o arquivo-special_media_post.php
Visite a página de permalinks (que irá liberá-la) e verifique novamente. O WordPress provavelmente só precisa ser estimulado para reconhecer sua adição à hierarquia.
Altere o código
De:
'has_archive' => true,
Para:
'has_archive' => false,
E, em seguida, vá para a página permalink, mude para o padrão e volte para o seu "link permanente"
% nome do post% /
Agora deve funcionar.
A razão pela qual não está indo para a única página {custom_post_type} .php é por causa do has_archive. Quando has_archive é definido como true, ele procura por archive- {custom_post_type} .php em vez da página única.
Espero que isso funcione.
É uma boa prática também usar register_activation_hook()
e register_deactivation_hook()
ao criar novos tipos de conteúdo.
Parece que novos tipos de conteúdo novos sempre não serão reescritos. Para evitar isso, insira no callback register_activation_hook () a função flush_rewrite_rules()
e seu novo conteúdo. Eu não sei porque, mas isso parece evitar esse problema. Olhe:
register_activation_hook( __FILE__, 'your_active_hook' );
function your_active_hook() {
special_media_post();
flush_rewrite_rules();
}
Copiei seu código, limpei as regras de regravação por meio do Admin e agora o Theme usa os modelos certos quando eu visito uma publicação de mídia.
Você precisa liberar as regras de reconfiguração uma vez usando o gancho after_switch_theme. Isso garantirá que as regras de reconfiguração sejam liberadas automaticamente depois que o usuário ativar o Tema.
Você pode usar este código (direto do Codex):
add_action( 'init', 'theme_prefix_cpt_init' );
function theme_prefix_cpt_init() {
register_post_type( ... );
}
function theme_prefix_rewrite_flush() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'theme_prefix_rewrite_flush' );
Por favor, consulte o WordPress Codex para mais informações: enlace
EDIT: Nesse caso, o Inspect Rewure Rules Plugin é muito útil, porque permite que você veja as regras conectadas ao seu tipo de post personalizado: enlace
Em uma nota, lembre-se também de que o local recomendado para colocar os tipos de postagem personalizados é um plug-in, não um tema.