• Hi! I haven’t been able to find any answers to this problem on other forums, so here goes:

    I’ve added half a dozen Custom Taxonomies to my site, all of which are working fine with the exception of one. It’s a film review site, so the Taxonomies are things like “Director,” “Producer,” “Writers,” “Country of Origin,” and so on. I used the same register_taxonomy function for each of these, which worked perfectly. However, the one Custom Taxonomy that is not working is the one for “Years.” I used the_terms functions to display the terms on each review page, so the visitor can click, e.g. “Japan” and see a list of all films using the term “Japan” within the “Country of Origin” taxonomy. However, when the visitor clicks a term within “Years” – e.g., 2010 – it goes to a “Not Found” page.

    Logically, the issue seems to be that all the other taxonomies use terms that are letter-based, and therefore strings. But all the terms added to the “Years” custom taxonomy are numbers, and, I’m assuming, therefore integers, which might be what’s causing them not to work.

    I am unsure as to how to fix this – I feel the solution might require somehow telling WordPress to interpret the “Years” terms as strings, and not as integers. But I don’t know whether it’s a change that needs to be made with my register_taxonomy function, my the_terms function, or something else entirely. Any help would be much appreciated!

    David

Viewing 11 replies - 1 through 11 (of 11 total)
  • register_taxinomy and the_terms are custom functions that you wrote, right? You might need to post them so that we can help you troubleshoot.

    Thread Starter david.bruggink

    (@davidbruggink)

    Good idea, thank you! πŸ™‚

    Here they are:

    1) Registering the custom taxonomy for “Year”:

    // Register Custom Taxonomy
    function year_taxonomy() {
    
    	$labels = array(
    		'name'                       => _x( 'Years', 'Taxonomy General Name', 'text_domain' ),
    		'singular_name'              => _x( 'Year', 'Taxonomy Singular Name', 'text_domain' ),
    		'menu_name'                  => __( 'Year', 'text_domain' ),
    		'all_items'                  => __( 'All Years', 'text_domain' ),
    		'parent_item'                => __( 'Parent Year', 'text_domain' ),
    		'parent_item_colon'          => __( 'Parent Year:', 'text_domain' ),
    		'new_item_name'              => __( 'New Year', 'text_domain' ),
    		'add_new_item'               => __( 'Add New Year', 'text_domain' ),
    		'edit_item'                  => __( 'Edit Year', 'text_domain' ),
    		'update_item'                => __( 'Update Year', 'text_domain' ),
    		'separate_items_with_commas' => __( 'Separate Years with commas', 'text_domain' ),
    		'search_items'               => __( 'Search Years', 'text_domain' ),
    		'add_or_remove_items'        => __( 'Add or remove years', 'text_domain' ),
    		'choose_from_most_used'      => __( 'Choose from the most used years', 'text_domain' ),
    		'not_found'                  => __( 'Not Found', 'text_domain' ),
    	);
    	$args = array(
    		'labels'                     => $labels,
    		'hierarchical'               => false,
    		'public'                     => true,
    		'show_ui'                    => true,
    		'show_admin_column'          => true,
    		'show_in_nav_menus'          => true,
    		'show_tagcloud'              => true,
    	);
    	register_taxonomy( 'year', array( 'post', 'review_post_type', 'article_post_type', 'news_post_type', 'interview_post_type' ), $args );
    
    }
    
    // Hook into the 'init' action
    add_action( 'init', 'year_taxonomy', 0 );

    2) Pulling the custom taxonomy terms for “Year” into the page:

    <div>
    
    	<?php the_terms( $post->ID, 'year', '<p class="post-taxonomy-title">Year</p> ', ' ' ); ?>
    
    </div>
    Thread Starter david.bruggink

    (@davidbruggink)

    Although I should clarify that register_taxonomy and the_terms are both WordPress functions and not my own custom functions:

    https://codex.wordpress.org/Function_Reference/register_taxonomy

    https://codex.wordpress.org/Function_Reference/the_terms

    Moderator keesiemeijer

    (@keesiemeijer)

    Try re-saving your permalink structure at wp-admin > Settings > Permalinks.

    How does the url for a year term look?

    Thread Starter david.bruggink

    (@davidbruggink)

    Resetting the permalinks did not work (good idea though).

    The url structure is:
    domain.com/year/1993/

    For example:
    domain.com/genre/drama/ is working fine and brings up a category-style archive of posts.

    Thread Starter david.bruggink

    (@davidbruggink)

    Each taxonomy also has a custom php file for its archive page: e.g., taxonomy-genre.php, taxonomy-year.php, and so on.

    The very odd thing is that one of the years actually kind of works. When I go to domain.com/year/2010/, it shows me an archive with one post, whereas every other year, as far as I know, doesn’t work. And of course, there are other films tagged with “2010” so it’s really not working 100%.

    Thread Starter david.bruggink

    (@davidbruggink)

    And just to further complicate things:
    When I’m in the Dashboard and exploring the “Years” taxonomy (in the same way that you would explore Posts > Tags) and seeing a table with Name, Description, Slug, and Count, it correctly displays the number of posts that are associated with each year. So for example “2008” shows that 42 posts are associated with it. But when I click “42” – which normally would list all the separate post titles – it shows me no posts.

    Moderator keesiemeijer

    (@keesiemeijer)

    WordPress thinks it’s a date archive because the taxonomy is a reserved term.
    https://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms

    Try naming the taxonomy ‘years’ and use the rewrite rule to set the permalink to ‘year’

    $args = array(
    		'labels'                     => $labels,
    		'hierarchical'               => false,
    		'public'                     => true,
    		'show_ui'                    => true,
    		'show_admin_column'          => true,
    		'show_in_nav_menus'          => true,
    		'show_tagcloud'              => true,
    		'rewrite' => array('slug' => 'year'),
    	);
    	register_taxonomy( 'years', array( 'post', 'review_post_type', 'article_post_type', 'news_post_type', 'interview_post_type' ), $args );

    Re-save your permalink structure after these changes

    Thread Starter david.bruggink

    (@davidbruggink)

    You, sir, are a genius!

    I believe that is the issue.

    However, when I rename the taxonomy, I lose all the “years” that have already been entered (which, unfortunately, there are hundreds of). Is there a way to change the name of the taxonomy while preserving the ones I’ve already entered?

    Thanks so much for the help.

    Moderator keesiemeijer

    (@keesiemeijer)

    By renaming your taxonomy from ‘year’ to ‘years’ the terms from the taxonomy are no longer visible.

    Try registering both taxonomies ‘year’ and ‘years’. This will bring back the terms from the ‘year’ taxonomy.

    Export all terms from the ‘year’ taxonomy to the ‘years’ taxonomy.
    https://wordpress.org/plugins/taxonomy-switcher/

    Make a database backup first.

    And as allways re-save your permalink structure when you’re done.

    Thread Starter david.bruggink

    (@davidbruggink)

    I will give that a try. You’re a life saver!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom Taxonomy – Number Terms go to "Not Found" Page’ is closed to new replies.