Support » Developing with WordPress » Taxonomy Template not Working

  • Good morning, I created a plugin for creating and getting a custom post type. Within the custom post type I added a taxonomy and now I have to create the relative template: taxonomy- $ taxonomy.php as explained here: https://developer.wordpress.org/themes/basics/template-hierarchy/# Custom_Taxonomies_display but it does not work and returns 404 (I have updated the permalink).
    I leave the code used, can you kindly help me?
    Thank you and good day.

    // Add taxonomy Comuni for ristrutturazioni_app
    if ( ! function_exists( 'lista_comuni_appartamenti' ) ) {
    
    function lista_comuni_appartamenti() {
    
    	$labels = array(
    		'name'                       => _x( 'Comuni Appartamenti', 'Taxonomy General Name', 'lista_comuni' ),
    		'singular_name'              => _x( 'Comune appartamenti', 'Taxonomy Singular Name', 'lista_comuni' ),
    		'menu_name'                  => __( 'Comuni appartamenti', 'lista_comuni' ),
    		'all_items'                  => __( 'All Items', 'lista_comuni' ),
    		'parent_item'                => __( 'Parent Item', 'lista_comuni' ),
    		'parent_item_colon'          => __( 'Parent Item:', 'lista_comuni' ),
    		'new_item_name'              => __( 'New Item Name', 'lista_comuni' ),
    		'add_new_item'               => __( 'Add New Item', 'lista_comuni' ),
    		'edit_item'                  => __( 'Edit Item', 'lista_comuni' ),
    		'update_item'                => __( 'Update Item', 'lista_comuni' ),
    		'view_item'                  => __( 'View Item', 'lista_comuni' ),
    		'separate_items_with_commas' => __( 'Separate items with commas', 'lista_comuni' ),
    		'add_or_remove_items'        => __( 'Add or remove items', 'lista_comuni' ),
    		'choose_from_most_used'      => __( 'Choose from the most used', 'lista_comuni' ),
    		'popular_items'              => __( 'Popular Items', 'lista_comuni' ),
    		'search_items'               => __( 'Search Items', 'lista_comuni' ),
    		'not_found'                  => __( 'Not Found', 'lista_comuni' ),
    		'no_terms'                   => __( 'No items', 'lista_comuni' ),
    		'items_list'                 => __( 'Items list', 'lista_comuni' ),
    		'items_list_navigation'      => __( 'Items list navigation', 'lista_comuni' ),
    		
    	);
    	
    	
    	$args = array(
    		'labels'                     => $labels,
    		'hierarchical'               => true,
    		'public'                     => true,
    		'show_ui'                    => true,
    		'show_admin_column'          => true,
    		'show_in_nav_menus'          => true,
    		'show_tagcloud'              => true,
    		'rewrite'      => array('slug' => 'comune', 'with_front' => false)
    	);
    	register_taxonomy( 'lista_comuni_appartamenti', array( 'ristrutturazione_app'), $args );
    
    }
    add_action( 'init', 'lista_comuni_appartamenti', 0 );
    
    }
    // End Add taxonomy Comuni for ristrutturazioni_app
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi, @smanimania

    Can you Please create template with name of “taxonomy-lista_comuni_appartamenti.php“.

    Thanks.

    Thread Starter smanimania

    (@smanimania)

    Hi, thank you for your reply and support, it doesn’t work, I receive a 404 error. The URL of the taxonomy’s term is: domain.it/ristrutturazione-appartamenti/comune/comune-di-prova-appartamenti/

    Thank you,
    Smanimania

    A template not existing will not cause a 404 error. If you don’t have the right template then WordPress will fall back to another template, as per the template hierarchy. You can never get a 404 from a missing template file. Just to make that clear.

    You say that the URL for the term is:

    domain.it/ristrutturazione-appartamenti/comune/comune-di-prova-appartamenti/

    However your taxonomy rewrite argument is just comune. Where is ristrutturazione-appartamenti coming from? Do you have your WordPress installed into a subdirectory?

    • This reply was modified 2 years, 8 months ago by Jacob Peattie.
    Thread Starter smanimania

    (@smanimania)

    Hi @jakept , “ristrutturazione-appartamenti” is the slug of a custom post type. WordPress is installed on the root of the domain.
    Thank You,
    Smanimania

    Moderator bcworkz

    (@bcworkz)

    If you want a list of posts (forgetting about type for now) with a particular term, you do not include the post type in the request. Do something like example.com/commune/comune-di-prova-appartamenti/

    Now, WP often has trouble with taxonomy term requests involving different post types. If you are not getting your post type returned with the above request, hook “pre_get_posts”. Check that the query is not admin and is the main query and that query var “comune” has a value. If all is true, set the “post_type” query var to an array of all post types that should be part of the query.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Taxonomy Template not Working’ is closed to new replies.