0

I have created a post type and I am trying to create a single page for that post type, I am creating a php file called single-job.php and it is using the index.php as a template. Below is my function for creating the post type:

add_action( 'init', 'register_cpt_job' );
function register_cpt_job() {

    $labels = array( 
        'name' => _x( 'Job posts', 'job' ),
        'singular_name' => _x( 'Job post', 'job' ),
        'add_new' => _x( 'Add New', 'job' ),
        'add_new_item' => _x( 'Add New Job post', 'job' ),
        'edit_item' => _x( 'Edit Job post', 'job' ),
        'new_item' => _x( 'New Job post', 'job' ),
        'view_item' => _x( 'View Job post', 'job' ),
        'search_items' => _x( 'Search Job posts', 'job' ),
        'not_found' => _x( 'No job posts found', 'job' ),
        'not_found_in_trash' => _x( 'No job posts found in Trash', 'job' ),
        'parent_item_colon' => _x( 'Parent Job post:', 'job' ),
        'menu_name' => _x( 'Job posts', 'job' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => true,

        'supports' => array( 'title', 'editor' ),
        'taxonomies' => array( 'category' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,


        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );

    register_post_type( 'job', $args );
}
2

First, before you start, just reflush your permalinks. It is sometimes strange why the Template Hierarchy fails. You code checks out, and should in theory work. Everything checks out, and to make sure, I tested it on my side.

You can use this work around to "force" wordpress to use a template. Here we would use template_include filter hook.

<?php
function wpse_template_include( $original_template ) {
    if ( isset( $wp->query_vars['job'] ) && false == $wp->query_vars['job']  ) {
        return get_template_directory() . '/single-job.php';
    } else {
        return $original_template;
    }
}

add_filter( 'template_include', 'wpse_template_include' );
| improve this answer | |
  • Hey I just tried this added it to the bottom of my functions.php and it doesnt work still! – Binney C Jun 26 '14 at 15:00
  • Are you looking for a single page or an archive page – Pieter Goosen Jun 26 '14 at 15:01
  • And are you using a child theme or parent theme – Pieter Goosen Jun 26 '14 at 15:02
  • Single im using <?php echo get_permalink(); ?> to get the link for the post and it is just 404ing and im using a parent theme – Binney C Jun 26 '14 at 15:03
  • 1
    what!!!! Thats such an annoying thing! thank you for that! – Binney C Jun 26 '14 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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