I have a custom post type set up (two, actually) that are not displaying properly. I am hoping that it is the same issue with both post types.

Here is my code for one of the post types (portfolio). The second is quite similar.

add_action('init', 'ccd_portfolio');

function ccd_portfolio() {

    $labels = array(
        'singular_name' => _x('Project', 'post type singular name'),
        'add_new' => _x('Add New', 'ccd_portfolio item'),
        'search_items' => __('Search Projects'),
        'parent_item_colon' => ''

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/images/icons/plugins/portfolio.png',
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'can_export' => true,
        'show_in_menu' => true,
        'has_archive' => true,

    register_post_type( 'portfolio' , $args );

add_action("admin_init", "ccdport_admin_init");

function ccdport_admin_init(){
  add_meta_box("mb_ccdport_details", "Project Details", "ccdport_details", "portfolio", "normal", "high");
  add_meta_box("mb_ccdport_client", "Client", "ccdport_client", "portfolio", "side", "high");

add_action( 'admin_enqueue_scripts', 'ccdport_add_datepicker' );
function ccdport_add_datepicker(){
  wp_enqueue_script( 'jquery-ui-datepicker' );
  wp_enqueue_style('jquery-datepicker-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
function ccdport_details(){
  global $post;
  $custom = get_post_custom($post->ID);
  $preview_url = $custom['preview_url'][0];
  $start_date = $custom['start_date'][0];
  $end_date = $custom['end_date'][0];
  <p><label>Preview URL: <strong>http://</strong>
    <input type="text" size="35" name="preview_url" value="<?php echo $preview_url; ?>" /></p>
  <p><label>Start date:</label>
    <input id="startDate" type="text" size="15" class="DatePicker" name="start_date" value="<?php echo $start_date; ?>" /> &nbsp;
    <label>End date:</label>
    <input id="endDate" type="text" size="15" class="DatePicker" name="end_date" value="<?php echo $end_date; ?>" /></p>
      jQuery(document).ready(function() {
          dateFormat : 'dd-mm-yyyy'

function ccdport_client(){
  global $post;
  $custom = get_post_custom($post->ID);
  $client = $custom['project_client'][0];
  $name = $custom['client_name'][0];
  $args = array(
    'post_type' => 'clients',
    'posts_per_page' => -1,
    'orderby' => 'name',
    'order' => 'ASC'
  <p><label>Client name</label></p>
  <input type="text" name="client_name" value="<?php echo $name; ?>" />
  $query = new WP_Query( $args );
  if ( $query->have_posts() ){
    echo '<select name="project_client">';
    while ( $query->have_posts() ){
      $slug = $post->post_name;
      echo '<option value="'.$slug.'" '.selected($slug, $client).'>'.get_the_title().' ('.$slug.')</option>';
    echo '</select>';
  else { echo '<p>There are currently no clients registered</p>'; }

add_action('save_post', 'ccdport_save_details');

function ccdport_save_details(){
  global $post;

  update_post_meta($post->ID, "client_name", $_POST["client_name"]);
  update_post_meta($post->ID, "project_client", $_POST["project_client"]);
  update_post_meta($post->ID, "portfolio", $_POST["portfolio"]);
  update_post_meta($post->ID, "preview_url", $_POST["preview_url"]);

Each post type is included in a separate file, and called to functions.php with an include command. These are showing up in the admin area perfectly, posts are being saved perfectly, etc. However, the theme files (archive-portfolio.php and single-portfolio.php) are not loading. Instead, my custom home page is being displayed.

I don't know what the issue would be. I have flushed the rewrite rules with each post type, and removing that does nothing either. I have only recently started with custom post types, so any assistance would be extremely helpful. I have had a look through the other answers and they don't seem to be helpful in my situation. I've tried resaving my permalinks, to no avail. I've tried changing 'has_archive' => true to 'has_archive' => 'portfolio', nothing. Is there something I have missed? More than likely something glaringly obvious?

  • Have you created a portfolio page with the following path: http://domain.com/portfolio? If so, try deleting it and then visiting that path. – deflime Jul 16 '14 at 20:46
  • No, I haven't. There is another post type that this is not working with (as mentioned earlier) which did have a page set up with the same slug (products). However, I renamed the page in Wordpress and that page is fine, but the corresponding custom post type is not. – Nate Jul 16 '14 at 20:49
  • I meant to put http://domain.com/work since you have a rewrite rule. I'm guessing same answer applies? So it's using your index.php file to render the page? – deflime Jul 16 '14 at 21:03
  • Yes, the same answer applies (I gathered you meant /work/ anyway), and no, it's a custom home page - page-home.php. I have a static home page set up which uses a custom template, and index.php handles my blog page. Sorry for not stating that, I didn't think it would have made a difference. I have a single.php and an archives.php page, neither of which are being loaded; it seems to be bypassing them all. Something tells me it may be a permalink issue somewhere, as /products/ throws up a 404 error, but /work/ gives my home page, and as I said, that uses a custom template. – Nate Jul 16 '14 at 21:07
  • However, I don't know for certain and have no idea where I would be looking or even if I am on the right lines, so thought best to ask for advice. – Nate Jul 16 '14 at 21:08

As per the OP's answer that was added in their question, I've separated it instead. In short:

...deactivating and reactivating plugins, commenting and uncommenting, I now have my site working as intended.

Here's the elaboration given by the OP as well:

I have a couple of custom post types in my functions.php file. Each one is in its own .php file to make them easier for me to manage and included in functions.php. However, I had a few issues with them, which was resolved. I had a space at the top of the page when I included more than one .php file. That was solved a short while ago, but as a temporary fix, I encased the pages in a if ( is_admin() ) function. I wasn't aware that would also affect the template pages as well.


I had a similar issue - added a new Custom Post Type whose slug was an old page. After permanently deleting the old page my custom posts and its archive wouldn't show up, instead I got the theme home page.

The solution was to go to Settings > Permalinks, change it to something else temporarily, press save, change it back to the original setting, press save again. Now the Custom Post Type is working.

Your Answer

