0

I create custom post type code is below

function jobs_post_type() {

    $labels = array(
        'name'                  => _x( 'Jobs', 'Post Type General Name', 'OceanWP' ),
        'singular_name'         => _x( 'Job', 'Post Type Singular Name', 'OceanWP' ),
        'menu_name'             => __( 'Jobs', 'OceanWP' ),
        'name_admin_bar'        => __( 'Job', 'OceanWP' ),
        'archives'              => __( 'Job Archives', 'OceanWP' ),
        'attributes'            => __( 'Job Attributes', 'OceanWP' ),
        'parent_item_colon'     => __( 'Parent Job:', 'OceanWP' ),
        'all_items'             => __( 'All Jobs', 'OceanWP' ),
        'add_new_item'          => __( 'Add New Job', 'OceanWP' ),
        'add_new'               => __( 'Add New', 'OceanWP' ),
        'new_item'              => __( 'New Job', 'OceanWP' ),
        'edit_item'             => __( 'Edit Job', 'OceanWP' ),
        'update_item'           => __( 'Update Job', 'OceanWP' ),
        'view_item'             => __( 'View Job', 'OceanWP' ),
        'view_items'            => __( 'View Jobs', 'OceanWP' ),
        'search_items'          => __( 'Search Jobs', 'OceanWP' ),
        'not_found'             => __( 'Not found', 'OceanWP' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'OceanWP' ),
        'featured_image'        => __( 'Featured Image', 'OceanWP' ),
        'set_featured_image'    => __( 'Set featured image', 'OceanWP' ),
        'remove_featured_image' => __( 'Remove featured image', 'OceanWP' ),
        'use_featured_image'    => __( 'Use as featured image', 'OceanWP' ),
        'insert_into_item'      => __( 'Insert into Job', 'OceanWP' ),
        'uploaded_to_this_item' => __( 'Uploaded to this Job', 'OceanWP' ),
        'items_list'            => __( 'Jobs list', 'OceanWP' ),
        'items_list_navigation' => __( 'Jobs list navigation', 'OceanWP' ),
        'filter_items_list'     => __( 'Filter Jobs list', 'OceanWP' ),
    );
    $rewrite = array(
        'slug'                  => 'career/jobs',
        'with_front'            => true,
        'pages'                 => true,
        'feeds'                 => true,
    );
    $args = array(
        'label'                 => __( 'Job', 'OceanWP' ),
        'description'           => __( 'Job Template', 'OceanWP' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'post-formats' ),
        'taxonomies'            => array( 'jobs', ' jobs_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 8,
        'menu_icon'             => 'dashicons-businessman',
        'rewrite'               => array( 'slug' => 'career/jobs' ),
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => false,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'rewrite'               => $rewrite,
        'capability_type'       => 'post',
    );
    register_post_type( 'jobs', $args );
    //flush_rewrite_rules();
}
add_action( 'init', 'jobs_post_type', 0 );

But slug doesn't work.

What is the solution for slug? I want to be domain.com/career/jobs/job-post-name

Thank you

1
  • Have you flushed permalinks? Just visit Settings > Permalinks and see if it works after that. Also, you've defined rewrite in the post type args twice. Jul 19 at 2:01

1 Answer 1

0

I tried your code and everything seems to work fine except 'rewrite' => $rewrite,, so I just commented this out, flushed permalinks and it works as expected.

So I have this

function jobs_post_type() {
    $labels = array(
        'name'                  => _x( 'Jobs', 'Post Type General Name', 'OceanWP' ),
        'singular_name'         => _x( 'Job', 'Post Type Singular Name', 'OceanWP' ),
        'menu_name'             => __( 'Jobs', 'OceanWP' ),
        'name_admin_bar'        => __( 'Job', 'OceanWP' ),
        'archives'              => __( 'Job Archives', 'OceanWP' ),
        'attributes'            => __( 'Job Attributes', 'OceanWP' ),
        'parent_item_colon'     => __( 'Parent Job:', 'OceanWP' ),
        'all_items'             => __( 'All Jobs', 'OceanWP' ),
        'add_new_item'          => __( 'Add New Job', 'OceanWP' ),
        'add_new'               => __( 'Add New', 'OceanWP' ),
        'new_item'              => __( 'New Job', 'OceanWP' ),
        'edit_item'             => __( 'Edit Job', 'OceanWP' ),
        'update_item'           => __( 'Update Job', 'OceanWP' ),
        'view_item'             => __( 'View Job', 'OceanWP' ),
        'view_items'            => __( 'View Jobs', 'OceanWP' ),
        'search_items'          => __( 'Search Jobs', 'OceanWP' ),
        'not_found'             => __( 'Not found', 'OceanWP' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'OceanWP' ),
        'featured_image'        => __( 'Featured Image', 'OceanWP' ),
        'set_featured_image'    => __( 'Set featured image', 'OceanWP' ),
        'remove_featured_image' => __( 'Remove featured image', 'OceanWP' ),
        'use_featured_image'    => __( 'Use as featured image', 'OceanWP' ),
        'insert_into_item'      => __( 'Insert into Job', 'OceanWP' ),
        'uploaded_to_this_item' => __( 'Uploaded to this Job', 'OceanWP' ),
        'items_list'            => __( 'Jobs list', 'OceanWP' ),
        'items_list_navigation' => __( 'Jobs list navigation', 'OceanWP' ),
        'filter_items_list'     => __( 'Filter Jobs list', 'OceanWP' ),
    );

    $args = array(
        'label'                 => __( 'Job', 'OceanWP' ),
        'description'           => __( 'Job Template', 'OceanWP' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'post-formats' ),
        'taxonomies'            => array( 'jobs', ' jobs_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 8,
        'menu_icon'             => 'dashicons-businessman',
        'rewrite'               => array( 'slug' => 'career/jobs' ),
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => false,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'post',
    );
    register_post_type( 'jobs', $args );
    //flush_rewrite_rules();
}
add_action( 'init', 'jobs_post_type', 0 );
2
  • Hi, I changed but I see that we have in Settings->Permalinks set up on /%category%/%postname%/ custom structure. This is a problem or not? Jul 19 at 8:10
  • Try, I used post name alone Jul 19 at 8:43

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.