I'm posting this as I found the problem, but it took me ages to find it with the mass of 'Refresh your permalinks' answers.
<?php
add_action( 'init', 'mytheme_create_post_type' );
function mytheme_create_post_type() { // jobs custom post type
// set up labels
$job_labels = array(
'name' => __( 'Jobs' ),
'singular_name' => __( 'Job' ),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Job' ),
'edit_item' => __( 'Edit Job' ),
'new_item' => __( 'New Job' ),
'all_items' => __( 'All Jobs' ),
'view_item' => __( 'View Job' ),
'search_items' => __( 'Search Jobs' ),
'not_found' => __( 'No Jobs Found' ),
'not_found_in_trash' => __( 'No Jobs found in Trash' ),
'parent_item' => __( 'Parent Job' ),
'parent_item_colon' => __( 'Parent Job:' ),
'menu_name' => __( 'Jobs' ),
);
register_post_type(
'job',
array(
'labels' => $job_labels,
'has_archive' => true,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ),
'taxonomies' => array( 'post_tag', 'job_category' ),
'exclude_from_search' => true,
'capability_type' => 'post'
)
);
register_taxonomy_for_object_type( 'job_category', 'job' );
}
add_action( 'init', 'mytheme_create_taxonomies', 5 );
function mytheme_create_taxonomies() {
// job taxonomy
$job_labels = array(
'name' => _x( 'Job Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Job Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Job Categories' ),
'all_items' => __( 'All Job Categories' ),
'parent_item' => __( 'Parent Job Category' ),
'parent_item_colon' => __( 'Parent Job Category:' ),
'edit_item' => __( 'Edit Job Category' ),
'update_item' => __( 'Update Job Category' ),
'add_new_item' => __( 'Add New Job Category' ),
'new_item_name' => __( 'New Job Category' ),
'menu_name' => __( 'Job Categories' ),
);
register_taxonomy(
'job_category',
'job',
array(
'hierarchical' => false,
'labels' => $job_labels,
'rewrite' => false,
'show_admin_column' => true
)
);
}
Given the problems with permalinks I'd turned everything off. I'd set Settings > Permalinks to default and set rewrite => false
for both the post type and the taxonomy.
However after creating a Job with a category of HR going to http://www.example.com/?job_category=hr gave me a 'Sorry no results found' i.e. not a 404 but no results for that category.
register_taxonomy_for_object_type
? – Tom J Nowell♦ Apr 25 '15 at 2:54