Reputation: 77
Hello I created an custom post type, and the single-custom_post_type showing the index page not the post type page..
I don't understand why it showing the index page..
I refreshed permalinks,i used: flush_rewrite_rules();
, but does not work
sigle-tv.php
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
test
<?php endwhile; endif; ?>
<!-- series -->
<?php get_footer(); ?>
register post type
function tvshows_taxonomy() {
register_taxonomy('tv_categories', array('tv,episodes',),
array(
'show_admin_column' => true,
'hierarchical' => true,
'rewrite' => array('slug' => get_option('tv-category')),)
);
}
add_action('init', 'tvshows_taxonomy', 0);
function prefijo_series() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'prefijo_series' );
// Register Series
function series() {
$labels = array(
'name' => _x( 'TV Shows', 'Post Type General Name', 'theme_name' ),
'singular_name' => _x( 'TV Show', 'Post Type Singular Name', 'theme_name' ),
'menu_name' => __( 'TV Shows', 'theme_name' ),
'name_admin_bar' => __( 'TV Shows', 'theme_name' ),
);
$rewrite = array(
'slug' => 'tv',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'TV Show', 'theme_name' ),
'description' => __( 'TV series manage', 'theme_name' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail','comments' ),
'taxonomies' => array( 'tv_categories' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-view-site',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'tv', $args );
}
add_action( 'init', 'series', 0 );
Can someone help me?
Upvotes: 1
Views: 58
Reputation: 77
Fixed, i included the register post type only for admin. THis was the problem
Upvotes: 0
Reputation: 496
Smith,
Your code is right nothing to change in it. Just go to backend admin section and click on Settings -> Permalinks After that select "Post Name" in radio buttons and click on Save Changes. Done.
Refresh your single page it will work.
Upvotes: 1
Reputation: 29308
I'm going to say your call to flush_rewrite_rules()
did not actually run. To be sure, add a quick manual flush to e.g. functions.php
:
/* Trigger on wp-admin or cron and whathaveyou */
add_action('admin_init', function() {
flush_rewrite_rules();
});
Flushing on init on a live site will degrade performance, etc. But it's useful to sanity check your flushes.
Upvotes: 0