So I have a project I am currently working on, where I have a WordPress set to a permalink structure of /blog/%postname% for blog posts and pages are domain.com/page-slug/
I have created a custom post type named “portfolio” which has an archive, but also have a page named “portfolio” which pulls the posts in the portfolio custom post type into it.
Now for the slug of the portfolio’s I have the custom rewrite set up, as I have to not align with front else the slug would have been /blog/portfolio/postname/ to my custom permalink structure of /blog/postname:
'rewrite' => array('slug' => 'portfolio', 'with_front' => false)
Which means the portfolio posts will be /portfolio/post-slug – but the issue is, going to /portfolio/ shows the archive and not the page.
How can I get it to show the portfolio page and not the archive?
Full custom post type function
function rbt_portfolio() {
$labels = array(
'name' => esc_html_x( 'Portfolios', 'Post Type General Name', 'jstest' ),
'singular_name' => esc_html_x( 'Portfolio', 'Post Type Singular Name', 'jstest' ),
'menu_name' => esc_html__( 'Portfolio', 'jstest' ),
'name_admin_bar' => esc_html__( 'Portfolio', 'jstest' ),
'archives' => esc_html__( 'Item Archives', 'jstest' ),
'parent_item_colon' => esc_html__( 'Parent Item:', 'jstest' ),
'all_items' => esc_html__( 'All Items', 'jstest' ),
'add_new_item' => esc_html__( 'Add New Item', 'jstest' ),
'add_new' => esc_html__( 'Add New', 'jstest' ),
'new_item' => esc_html__( 'New Item', 'jstest' ),
'edit_item' => esc_html__( 'Edit Item', 'jstest' ),
'update_item' => esc_html__( 'Update Item', 'jstest' ),
'view_item' => esc_html__( 'View Item', 'jstest' ),
'search_items' => esc_html__( 'Search Item', 'jstest' ),
'not_found' => esc_html__( 'Not found', 'jstest' ),
'not_found_in_trash' => esc_html__( 'Not found in Trash', 'jstest' ),
'featured_image' => esc_html__( 'Featured Image', 'jstest' ),
'set_featured_image' => esc_html__( 'Set featured image', 'jstest' ),
'remove_featured_image' => esc_html__( 'Remove featured image', 'jstest' ),
'use_featured_image' => esc_html__( 'Use as featured image', 'jstest' ),
'inserbt_into_item' => esc_html__( 'Insert into item', 'jstest' ),
'uploaded_to_this_item' => esc_html__( 'Uploaded to this item', 'jstest' ),
'items_list' => esc_html__( 'Items list', 'jstest' ),
'items_list_navigation' => esc_html__( 'Items list navigation', 'jstest' ),
'filter_items_list' => esc_html__( 'Filter items list', 'jstest' ),
);
$args = array(
'label' => esc_html__( 'Portfolio', 'jstest' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-index-card',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'portfolio', 'with_front' => false),
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'portfolio', $args );
}
add_action( 'init', 'rbt_portfolio', 0 );
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
How can I get it to show the portfolio page and not the archive?
-
As pointed in the comments, just set
has_archivetofalse. - But after that, be sure to flush the rewrite rules – just visit the permalink settings admin page.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0