I have a category on my website called ‘profiles’ I am in the process of moving this category to a custom post type called ‘profiles’.

My problem is I cannot get the archive page to show for this custom post type. When I go to the url mywebsite.com/profiles it takes me to a single post page for a post in the profiles category.

I have included has_archive = true; in my functions.php

I didn’t have a problem creating an archive page for another custom post type I did on the same website so Im really lost as to why this is not working this time.

Any advice would be most appreciated?

add_action( 'init', 'profile_custom_init' );

/* Here's how to create your customized labels */
function profile_custom_init() {
$labels = array(
    'name' => _x( 'Profiles', 'post type general name' ), // Tip: _x('') is used for localization
    'singular_name' => _x( 'Profile', 'post type singular name' ),
    'add_new' => _x( 'Add New', 'Profile' ),
    'add_new_item' => __( 'Add Profile' ),
    'edit_item' => __( 'Edit Profile' ),
    'new_item' => __( 'New Profile' ),
    'view_item' => __( 'View Profile' ),
    'search_items' => __( 'Search Profile' ),
    'not_found' =>  __( 'No Profile found' ),
    'not_found_in_trash' => __( 'No Profile found in Trash' ),
    'parent_item_colon' => ''
);

// Create an array for the $args
$args = array( 'labels' => $labels, /* NOTICE: the $labels variable is used here... */
    'public' => true,
    'publicly_queryable' => true,
    'has_archive' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => 10,
    'supports' => array( 'title', 'editor','thumbnail', 'excerpt', 'custom-fields' ),
        'taxonomies' => array('category')
    ); 

    register_post_type( 'profile', $args ); /* Register it and move on */
}

2

  1. Navigate to Settings -> permalinks
  2. Change the permalink structure to Default
  3. Save settings
  4. Change to custom structure or post name (or any other structure)
  5. Save Settings

This will re-write the htaccess file and then the re-write should work.


If the above solution doesn’t work – it should be related to server configuration.

Aapache2

Run: a2enmod rewrite && service apache2 reload

Nginx

Follow: https://do.co/2LjCF8r


I hope this will save your time.

Leave a Reply

Your email address will not be published. Required fields are marked *