I'm new here. I badly need help on this permalink issue. In my site I've one custom post type 'portfolio' but when I set the permalink structure to 'Post name' it returns loads index.php page not its page-portfolio.php page. But with other permalink structure it works fine.

Sorry I tried but there were no similar answers. I'm running on my wamp server which has mod-rewrite rules enabled and I can change permalink structures (to 'Post name') for other themes (with custom post types) and that works smoothly.

There is may be some trouble in my codes. Please help. Thank you in advance for your kind time and support.

* Custom Post types for Portfolios!
function jm_portfolio_post_type(){
    $labels = array(
        'name'          => _x('Portfolio', 'post type general name'),
        'singular_name' => _x('Portfolios', 'post type singular name'),
        'add_new'       => _x('Add New', 'Portfolio'),
        'add_new_item'  => __('Add New Portfolio'),
        'edit_item'     => __('Edit Portfolio'),
        'new_item'      => __('New Portfolio'),
        'all_items'     => __('All Portfolios'),
        'view_item'     => __('View Portfolio'),
        'search_items'  => __('Search Portfolios'),
        'not_found'     => __('No portfolios found'),
        'not_found_in_trash' => __('No portfolios found in the Trash'),
        'parent_item_colon' => '',
        'menu_name'     => 'Portfolio'

    $args = array(
        'labels'        => $labels,
        'description'   => 'Portfolio',
        'public'        => true,
        'menu_position' => 5,
        'menu_icon'     => null,
        'hierarchical'  => true,
        'supports'      => array('title', 'editor', 'thumbnail'),
        'rewrite'       => array('slug' => 'portfolio'),
        'has_archive'   => true
    register_post_type('portfolio', $args);

add_action('init', 'jm_portfolio_post_type');

* Custom Messages for Portfolio
function jm_portfolio_updated_messages($messages){
    global $post, $post_ID;
    $messages['portfolio'] = array(
        0   => '',
        1   => sprintf(__('Portfolio updated. View portfolio'), esc_url(get_permalink($post_ID))),
        2   => __('Custom field updated.'),
        3   => __('Custom field updated.'),
        4   => __('Portfolio updated.'),
        5   => isset($_GET['revision']) ? sprintf(__('Portfolio restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
        6   => sprintf(__('Portfolio published. View portfolio'), esc_url(get_permalink($post_ID))),
        7   => __('Portfolio saved.'),
        8   => sprintf(__('Portfolio submitted. Preview portfolio'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
        9   => sprintf(__('Portfolio scheduled for: %1$s. Preview portfolio'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
        10  => sprintf(__('Portfolio draft updated. Preview portfolio'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
    return $messages;

add_filter('post_updated_messages', 'jm_portfolio_updated_messages');

function jm_rewrite_flush() {
add_action( 'after_switch_theme', 'jm_rewrite_flush' );
  • 2
    what happens if you correct the rewrite argument? it should be 'rewrite' => array('slug' => 'portfolio') – Milo Apr 7 '14 at 19:02
  • @Milo Thank you for the help. I've changed and updated the codes here (above). But still the same problem. – Nuruzzaman Sheikh Apr 7 '14 at 19:09
  • the template for a single portfolio item should be single-portfolio.php. your code works as expected in the twenty thirteen theme, verify that you also have the issue with a core bundled theme and are using the correct template to render single portfolio items. – Milo Apr 7 '14 at 19:16
  • @Milo yes I've have that single-portfolio.php file and if I browse this location localhost/jm/portfolio/bmw-sedan it just loads fine but if I browse localhost/jm/portfolio then it only returns the homepage never loads the page-portfolio.php I've named and selected this theme correctly from the wp admins page creation section. Please help me if you can. – Nuruzzaman Sheikh Apr 8 '14 at 2:24
  • @Milo And I just ported my portfolio codes into wp default 14 theme it acts the same as of with my theme. (the page-portfolio.php don't loads it loads the index page). – Nuruzzaman Sheikh Apr 8 '14 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.