Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created a custom post type with the following code:

add_action('init', 'create_trans_career');

function create_trans_career() {
    //Arguments to create post type.
    $args = array(
        'labels' => array(
            'name' => __('Career', 'trans'),
            'singular_name' => __('Career', 'trans'),
            'add_new' => __('Add New', 'trans'),
            'add_new_item' => __('Add New Career Item', 'trans'),
            'edit' => __('Edit', 'trans'),
            'edit_item' => __('Edit Career Item', 'trans'),
            'new_item' => __('New Career', 'trans'),
            'view' => __('View', 'trans'),
            'view_item' => __('View Career', 'trans'),
            'search_items' => __('Search Career', 'trans'),
            'not_found' => __('No Career item found', 'trans'),
            'not_found_in_trash' => __('No Career item found in Trash', 'trans'),
        ),
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'has_archive' => true,
        'menu_icon' => get_bloginfo('template_directory'). '/images/career-icon.png',
        'supports' => array('title', 'editor', 'thumbnail'),
        'rewrite' => array('slug' => 'career', 'with_front' => false),
    );

    //Register type and custom taxonomy for type.
    register_post_type( 'career' , $args );
}

I also created a single page (single-career.php):

<?php while ( have_posts() ) : the_post(); ?>
            <h2 class="page-title"><?php the_title(); ?></h2>
            <hr />
            <?php the_content('Read More...'); ?>
            <a href="<?php bloginfo('wpurl'); ?>/career" title="<?php _e('Back to jobs listings', 'trans'); ?>" class="back-to-jobs"><?php _e('Back to jobs listings', 'trans'); ?></a>
            <?php endwhile;  ?>

..and a page template to list the posts:

$mypost = array( 'post_type' => 'career', 'posts_per_page' => 10, 'paged' => $pagedNum );
            $loop = new WP_Query( $mypost ); ?>
            <?php while ( $loop->have_posts() ) : $loop->the_post();?>
            <tr id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <td><?php the_title(); ?></td>
                <td><?php echo $location; ?></td>
                <td><?php echo $close_date; ?></td>
                <td><a href="<?php the_permalink(); ?>" title="<?php _e('Details', 'trans'); ?>"><?php _e('&gt; Details', 'trans'); ?></a></td>
                <td class="apply-now"><a data-title="<?php the_title(); ?>" data-location="<?php echo $location; ?>" href="#apply_<?php the_ID(); ?>" title="<?php _e('Apply Now', 'trans'); ?>" class="career-apply"><?php _e('Apply Now', 'trans'); ?></a></td>
            </tr>
            <?php endwhile;  ?>

I created a page with jobs using the template above.. it's working I see all posts.. but when I open a single page I receive 404 error. Where is the problem?

share|improve this question
1  
What URL is it trying to reach when it 404s? –  vancoder Apr 9 '13 at 21:57
1  
Did you refresh permalink settings? –  Chris_O Apr 9 '13 at 21:59
    
career/test-job-title –  Rinoleti Apr 9 '13 at 21:59
    
How can I refresh and why is it necessary? –  Rinoleti Apr 9 '13 at 22:00
1  
To refresh simply visit the permalinks page in settings. It will make sure all of your pretty permalinks (including /career/) are upto date. –  vancoder Apr 9 '13 at 22:11

1 Answer 1

Add this to your functions.php:

/* Flush rewrite rules for custom post types. */
add_action( 'after_switch_theme', 'bt_flush_rewrite_rules' );

/* Flush your rewrite rules */
function bt_flush_rewrite_rules() {
     flush_rewrite_rules();
}

Then change your theme to a different theme and then set it back again to your custom theme. This will flush the rewrite rule and making the custom post working properly.

share|improve this answer
    
followed your instructions but not working :( –  itskawsar May 2 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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