Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Here’s my Taxonomy:

    add_action( 'init', 'register_taxonomy_locations' );
    
    function register_taxonomy_locations() {
    
        $labels = array(
            'name' => _x( 'Locations', 'locations' ),
            'singular_name' => _x( 'Location', 'locations' ),
            'search_items' => _x( 'Search Locations', 'locations' ),
            'popular_items' => _x( 'Popular Locations', 'locations' ),
            'all_items' => _x( 'All Locations', 'locations' ),
            'parent_item' => _x( 'Parent Location', 'locations' ),
            'parent_item_colon' => _x( 'Parent Location:', 'locations' ),
            'edit_item' => _x( 'Edit Location', 'locations' ),
            'update_item' => _x( 'Update Location', 'locations' ),
            'add_new_item' => _x( 'Add New Location', 'locations' ),
            'new_item_name' => _x( 'New Location', 'locations' ),
            'separate_items_with_commas' => _x( 'Separate locations with commas', 'locations' ),
            'add_or_remove_items' => _x( 'Add or remove locations', 'locations' ),
            'choose_from_most_used' => _x( 'Choose from the most used locations', 'locations' ),
            'menu_name' => _x( 'Locations', 'locations' ),
        );
    
        $args = array(
            'labels' => $labels,
            'public' => true,
            'show_in_nav_menus' => true,
            'show_ui' => true,
            'show_tagcloud' => true,
            'show_admin_column' => false,
            'hierarchical' => true,
    
            'rewrite' => true,
            'query_var' => true
        );
    
        register_taxonomy( 'locations', array('states', 'post', 'school'), $args );
    }

    And here’s my CPT:

    add_action( 'init', 'register_cpt_states' );
    
    function register_cpt_states() {
    
        $labels = array(
            'name' => _x( 'Demographics', 'states' ),
            'singular_name' => _x( 'Demographic', 'states' ),
            'add_new' => _x( 'Add New', 'states' ),
            'add_new_item' => _x( 'Add New Demographic', 'states' ),
            'edit_item' => _x( 'Edit Demographic', 'states' ),
            'new_item' => _x( 'New Demographic', 'states' ),
            'view_item' => _x( 'View Demographic', 'states' ),
            'search_items' => _x( 'Search Demographics', 'states' ),
            'not_found' => _x( 'No demographics found', 'states' ),
            'not_found_in_trash' => _x( 'No demographics found in Trash', 'states' ),
            'parent_item_colon' => _x( 'Parent Demographic:', 'states' ),
            'menu_name' => _x( 'Demographics', 'states' ),
        );
    
        $args = array(
            'labels' => $labels,
            //'description' => 'Yo Whatup?',
            'hierarchical' => true,
            'menu_icon'    => 'dashicons-location-alt',
            'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes' ),
            'taxonomies' => array( 'locations', 'location_types' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'menu_position' => 5,
    
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'post'
        );
    
        register_post_type( 'states', $args );
    }

    I’m still getting the 404 error as everyone else when using hierarchal taxonomy’s. I’m on WP 4.1 using version 0.9.6 of the Custom Post Type Permalink plugin.

    Here’s my permalink structure for my CPT:
    /%locations%/%postname%/

    My posts are generating the correct permalinks, but they return 404 pages when I try to view them. For example, my locations taxonomy is listed out hierarchal by state / county / city and when I create a new post in my school CPT I tag it respectively. The permalink structure is generated properly (domain.com/school/state/city/county/post-name), but I get a 404 page when I try and view it.

    Not sure why I’m getting the 404. It works fine if I only give the post the top level taxonomy, but whenever I give it multiple taxonomy’s in the hierarchy I get a 404. I’ve flushed the rewrite rules several times and I’ve toggled the “Use custom permalink of custom taxonomy archive” options with no luck.

    Any ideas?

    I’ve also had the same issue. Has anyone found a workaround for this?

    Excellent, thank you! Using this to get the categories from my CPT.

    $cats = get_object_taxonomies('publication', 'names');
    foreach($cats as $cat) {
         $tax_terms = get_terms($cat, array( 'hide_empty' => 0 ));
         print_r($tax_terms);
    }

    That worked like a charm, thanks for the post.

Viewing 5 replies - 1 through 5 (of 5 total)