0

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 );
2
  • 1
    If you do not need the archive, could you set 'has_archive' => false?
    – Howdy_McGee
    Commented Mar 23, 2021 at 20:10
  • @Howdy_McGee disabling 'has_archive' => false seem to then only show the blog post archive instead of the page that is created. Commented Mar 23, 2021 at 20:12

1 Answer 1

1

How can I get it to show the portfolio page and not the archive?

  1. As pointed in the comments, just set has_archive to false.

  2. But after that, be sure to flush the rewrite rules - just visit the permalink settings admin page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.