WordPress.org

Forums

Page not found on custom taxonomy page (4 posts)

  1. Cultivate
    Member
    Posted 1 year ago #

    Hi,
    I have setup a custom post type that has two custom taxonomies associated with it. The code below is in the themes function file. The custom post type is for a series of products (mha-products) which will be categorised by type (product_type) and application (applications).

    Under products i will display a list of categories before drilling down into the list of products. Applications will display a list of all applications then link to a page about the individual application.

    Within my theme i have the following template files:

    • archive-mha-products.php
    • taxonomy-applications.php
    • taxonomy-product_type.php
    • single-mha-products.php

    I am currently getting a "page not found" for /applications but everything is working correctly for /products.

    Heres the products section and heres the applications section

    Any help appreciated.

    Functions code:

    //
    // Custom Post Types
    // ================================================== -->
    //
    	function create_my_post_types() {
      	//Post type name
    		register_post_type( 'mha-products',
    			array(
    				'labels' => array(
    					'name' => _x('Products', 'post type general name'),
    					'singular_name' => _x('Product', 'post type singular name'),
    					'add_new' => _x('Add Product', 'product'),
    					'add_new_item' => __('Add New'),
    					'edit_item' => __('Edit Product'),
    					'new_item' => __('New Product'),
    					'all_items' => __('All Products'),
    					'view_item' => __('View Product'),
    					'search_items' => __('Search Products'),
    					'not_found' =>  __('Nothing found'),
    					'not_found_in_trash' => __('Nothing found in Trash'),
    					'parent_item_colon' => '',
    					'menu_name' => __('Products')
    				),
    				'public' => true,
    				'publicly_queryable' => true,
    				'query_var' => true,
    				'menu_icon' => 'dashicons-lightbulb', // Get icons from here WordPress 3.8 only - http://melchoyce.github.io/dashicons/
    
    				'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
    				'rewrite' => array( 'slug' => 'products', 'with_front' => 'false' ), //Slug must be diffferent to page name
    				'menu_position' => 5,
    				'has_archive' => true
    			)
    		);
    	}
    
    //
    // Custom Taxonomies
    // ================================================== -->
    //
    	function build_taxonomies() {
    	    // Add new Product type taxonomy, make it hierarchical (like categories)
    	    $productlabels = array(
    		    'name' => _x( 'Product Type', 'taxonomy general name' ),
    		    'singular_name' => _x( 'Product Type', 'taxonomy singular name' ),
    		    'search_items' =>  __( 'Search Product Types' ),
    		    'all_items' => __( 'All Product Types' ),
    		    'edit_item' => __( 'Edit Product Type' ),
    		    'update_item' => __( 'Update Product Type' ),
    		    'add_new_item' => __( 'Add New Product Type' ),
    		    'new_item_name' => __( 'New Product Type Name' ),
    		    'menu_name' => __( 'Product Type' ),
    	    ); 
    
    	    register_taxonomy('product_type',
    	    	array('mha-products'),
    	    		array(
    				    'hierarchical' => true,
    				    'labels' => $productlabels,
    				    'show_ui' => true,
    				    'show_admin_column' => true,
    				    'query_var' => true,
    				    'has_archive' => true,
    				    'rewrite' => array( 'slug' => 'products/type', 'with_front' => false),
    				   	'show_in_nav_menus' => true,
    			    )
    		);
    
    		// Add new Application taxonomy, make it hierarchical (like categories)
    	    $applicationlabels = array(
    		    'name' => _x( 'Applications', 'taxonomy general name' ),
    		    'singular_name' => _x( 'Application', 'taxonomy singular name' ),
    		    'search_items' =>  __( 'Search Applications' ),
    		    'all_items' => __( 'All Applications' ),
    		    'edit_item' => __( 'Edit Application' ),
    		    'update_item' => __( 'Update Application' ),
    		    'add_new_item' => __( 'Add New Application' ),
    		    'new_item_name' => __( 'New Application Name' ),
    		    'menu_name' => __( 'Applications' ),
    	    ); 
    
    	    register_taxonomy('applications',
    	    	array('mha-products'),
    	    		array(
    				    'hierarchical' => true,
    				    'labels' => $applicationlabels,
    				    'show_ui' => true,
    				    'show_admin_column' => true,
    				    'query_var' => true,
    				    'has_archive' => true,
    				    'rewrite' => array( 'slug' => 'applications', 'with_front' => false),
    				   	'show_in_nav_menus' => true,
    			    )
    		);
    	}
  2. bitwit
    Member
    Posted 1 year ago #

    Hey,

    Just a couple ideas for troubleshooting:

    1. Have you tried removing products_type and doing just applications and checking if it works alone?
    2. I notice your slug for products is 'products/type' and applications is 'applications'. Why is it 'products/type' for products?

  3. michelabdo
    Member
    Posted 9 months ago #

    Just place the taxonomies function above the custom post type.

  4. Rushang
    Member
    Posted 3 months ago #

    Even I was facing the same issue and the solution by michelabdo worked perfectly.

    I will like to know how it works. Why do we have to place custom taxonomy function above custom post type?

Topic Closed

This topic has been closed to new replies.

About this Topic