0

I've created a couple of custom post types:

add_action( 'init', 'register_post_types' );
function register_post_types() {
    register_post_type(
        'jobsearch-post',
        array(
            'labels' => array(
            'name' => __( 'Job Searches Post' ),
            'singular_name' => __( 'Job Search Post' )
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array(
            'slug' => 'jobsearch'
        )
    )
);
register_post_type(
    'recruiters-post',
    array(
        'labels' => array(
            'name' => __( 'Recruiters Post' ),
            'singular_name' => __( 'Recruiter Post' )
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array(
            'slug' => 'recruiters'
        )
    )
);
}

Which appear to be working correctly. However, I have a couple of related taxonomies:

add_action( 'init', 'register_taxonomies' );
function register_taxonomies() {
register_taxonomy(
    'recruiters-tax',
    array (
        0 => 'recruiters-post',
    ),
    array(
        'hierarchical' => true,
        'label' => 'Recruiters Taxonomy',
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array(
            'slug' => ''
        ),
        'singular_label' => 'Recruiter Taxonomy'
    )
);
register_taxonomy(
    'jobsearch-tax',
    array (
        0 => 'jobsearch-post',
    ),
    array(
        'hierarchical' => true,
        'label' => 'Job Searches Taxonomy',
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array(
            'slug' => ''
        ),
        'singular_label' => 'Job Search Taxonomy'
    )
);
}

As you can see these are hierarchical. Unfortunately, though, I get a 404 ONLY if I try to access items within the recruiters taxonomy, e.g: http://localhost:8888/recruiters/some-category

I can access job postings: http://localhost:8888/jobsearch/some-category

And I can also access the root custom post types: http://localhost:8888/recruiters http://localhost:8888/jobsearch

Is there something I'm missing that is preventing me from reaching nested taxonomies from only the recruiters taxonomy?

Note that I have been constantly hitting the "Save Changes" button in my permalink settings in between trying to get this to work.

This is driving me crazy!

  • It appears if I swap the order of the two register_taxonomy() calls it instead 404's for jobsearch sub taxonomies. Is my first call getting somehow overwritten by the second? – user38502 Sep 24 '13 at 0:32
0

After registering custom taxonomies for custom post types. Use register_taxonomy_for_object_type() right after the function to interconnect them.

The reference link are Register Taxonomy, the usage part has an explanation regarding this.

Register Taxonomy for object type

Hope it helps!

  • Unfortunately it's still not working. I used null for the $object_type in the two register_taxonomy calls and then called register_taxonomy_for_object_type immediately after, and everything functions the same as it did before. One other thing I found is that if I go to a sub taxonomy page (some-category in my example above) and click View Category in the WP backend it sends me to a 404 page as well (again, just for recruiters but not jobsearch). – user38502 Sep 24 '13 at 14:24
0

I think the problem came from the empty rewrite slug for the taxonomies. Since WP didn't know how to differentiate the two taxonomies with separate urls, it just guessed with the first one and gave up on the second since it didn't see a difference. Adding a rewrite slug fixed it for me.

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.