0

I've been writing up some code which enables two post types to share a custom taxonomy. From the admin side, it works fantastically - but for some reason, when I look at the taxonomy archive itself on the site,

/country/{country} , despite the fact that there are two posts (one from each type) in the taxonomy, it comes back with 'No posts found' but not a 404 error. I wonder if I've missed something to make it work - my code is below.

register_taxonomy(
        'country',
        array('hotels', 'attractions'),
        array(
            'label' => __( 'Country' ),
            'hierarchical' => true,
            'sort' => true,
            'args' => array( 'orderby' => 'term_order' ),
            'rewrite' => array( 'slug' => 'country' )
        )
    );
5
  • Did you update the permalink structure after making the changes? You might need to visit the permalinks settings page and update (no changes need to be made, visiting it might be enough but I'd click the update button to be sure). May 30, 2012 at 8:52
  • I did - and that made the other sections (the individual posts) work great - but hasn't done anything for the archive pages for some reason. May 30, 2012 at 9:07
  • @iampearce post your custom types creation scripts. Jun 4, 2012 at 18:46
  • Are both post types custom posttypes or is one a 'post'?
    – janw
    Jun 4, 2012 at 19:10
  • as @iampearce says, please post more code. Post the full function you're using to register the taxonomy and post types.
    – mrwweb
    Jun 5, 2012 at 18:02

3 Answers 3

0
+50

As the page is returning with "no posts found", it's possible that whatever template page is generating term archives isn't including your custom post types in its query.

If you take a look at the template that should be easy to see.

0

Your will need to edit the taxonomy page. By default it will only get 'post' not custom post types.

Adjust the query which has run on the page with the right posttypes. http://codex.wordpress.org/Class_Reference/WP_Query#Type_.26_Status_Parameters

-1

Not sure what do you mean by "two post types to share a custom taxonomy". As I understand correct you can try to add to functions.php something like this:

function customposttype_rewrites($wp_rewrite) {
    $newrules = array();
    $newrules['country/([^/]+)/?$'] = 'index.php?name=$matches[1]&taxonomy=country&term=$matches[1]';

    $wp_rewrite->rules = $newrules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'customposttype_rewrites');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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