“Post name” permalink returns home page for custom posts

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.

Read More

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() {
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'jm_rewrite_flush' );

Related posts

Leave a Reply