1

I have the following code in my functions.php file:-

/**
 *  Register Add Job
 *
 */

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

    $labels = array(
        'name'               => _x( 'Jobs', 'post type general name', 'engwp' ),
        'singular_name'      => _x( 'Jobs', 'post type singular name', 'engwp' ),
        'menu_name'          => _x( 'Jobs', 'admin menu', 'engwp' ),
        'name_admin_bar'     => _x( 'Jobs', 'add new on admin bar', 'engwp' ),
        'add_new'            => _x( 'Add New Job', 'Property', 'engwp' ),
        'add_new_item'       => __( 'Add New Job', 'engwp' ),
        'new_item'           => __( 'New Job', 'engwp' ),
        'edit_item'          => __( 'Edit Job', 'engwp' ),
        'view_item'          => __( 'View Jobs', 'engwp' ),
        'all_items'          => __( 'All Jobs', 'engwp' ),
        'search_items'       => __( 'Search Jobs', 'engwp' ),
        'parent_item_colon'  => __( 'Parent Jobs:', 'engwp' ),
        'not_found'          => __( 'No Jobs found.', 'engwp' ),
        'not_found_in_trash' => __( 'No Jobs found in Trash.', 'engwp' )
    );

    $args = array(
        'description'         => __( 'Jobs', 'engwp' ),
        'labels'          => $labels,
        'supports'        => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ),
        'hierarchical'          => true,
        'public'            => true,
        'publicly_queryable'    => true,
        'query_var'         => true, 
        'show_ui'           => true,
        'menu_icon'         => 'dashicons-universal-access-alt',
        'show_ui'             => true,
        'show_in_menu'          => true,
        'show_in_nav_menus' => true,
        'show_in_admin_bar' => true,
        'menu_position' => 31,
        'can_export'        => true,
        'has_archive' => 'jobs/[^/]+/[^/]+',
        'exclude_from_search'   => false,
        'capability_type'   => 'post',
        'taxonomies'          => array( 'category' ),
    );

    register_post_type( 'jobs', $args );

}

I've added 'has_archive' => 'jobs/[^/]+/[^/]+', as I want to show the archive-jobs.php if you were on website.com/jobs, website.com/jobs/value and website.com/jobs/value/value2

With the above code, I can access the jobs by going to website.com/jobs/value/value2 but not when I go to website.com/jobs/value.

Is there a way to get both URL's working?

If I change has_archive to 'has_archive' => 'jobs/[^/]+/[^/]+', it will work the opposite way around, so website.com/jobs/value would work and website.com/jobs/value/value2 wouldn't.

Please advise.

Your Answer

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

Browse other questions tagged or ask your own question.