Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter WADSpot

    (@spotoremor)

    i tried to go through your code and have a suggestion if you can possibly add a filter in Permalink.php like the following in create_taxonomy_replace_tag()? (this is between line 175 and 178)

    $replace = apply_filters('cptp_create_taxonomy_replace',$replace,$taxonomies,$post_id , $permalink);
    return array("search" => $search, "replace" => $replace );

    so in functions.php of a theme, the following can be added to customize the processing of $replace:

    function spot_cptp_create_taxonomy_replace($replace,$taxonomies,$post_id , $permalink){
    
    		foreach ( $taxonomies as $taxonomy => $objects ) {
    			$term = null;
    			if ( strpos($permalink, "%$taxonomy%") !== false ) {
    				$terms = wp_get_post_terms( $post_id, $taxonomy, array('orderby' => 'term_id'));
    
    				if ( $terms and count($terms) > 1 ) {
    					if(reset($terms)->parent == 0){
    
    						$keys = array_keys($terms);
    						$term = $terms[$keys[1]]->slug;
    						if ( $terms[$keys[0]]->term_id == $terms[$keys[1]]->parent ) {
    							$term = CPTP_Util::get_taxonomy_parents( $terms[$keys[1]]->parent,$taxonomy, false, '/', true ) . $term;
    						}
                if(count($terms) > 2){
                $term = $terms[$keys[2]]->slug;
                  if ( $terms[$keys[1]]->term_id == $terms[$keys[2]]->parent ) {
                    $term = CPTP_Util::get_taxonomy_parents( $terms[$keys[2]]->parent,$taxonomy, false, '/', true ) . $term;
                  }
                }
    					}else{
    						$keys = array_keys($terms);
    						$term = $terms[$keys[0]]->slug;
    						if ( $terms[$keys[1]]->term_id == $terms[$keys[0]]->parent ) {
    							$term = CPTP_Util::get_taxonomy_parents( $terms[$keys[0]]->parent,$taxonomy, false, '/', true ) . $term;
    						}
    					}
    				}else if( $terms ){
    
    					$term_obj = array_shift($terms);
    					$term = $term_obj->slug;
    
    					if(isset($term_obj->parent) and $term_obj->parent != 0) {
    						$term = CPTP_Util::get_taxonomy_parents( $term_obj->parent,$taxonomy, false, '/', true ) . $term;
    					}
    				}
    
    				if( isset($term) ) {
              $replace = array($term);
    				}
    
    			}
    		}
    
      return $replace;
    }
    add_filter('cptp_create_taxonomy_replace','spot_cptp_create_taxonomy_replace',10,4);

    fixed 0.9.6

    Thread Starter WADSpot

    (@spotoremor)

    great job!

    i can see the third-level category now.

    again, thank you.

    Not for me, i don’t know why… an idea ?

    Thread Starter WADSpot

    (@spotoremor)

    try checking your post type permalink settings, and make sure that you included the taxonomy name as part of your permalink string.

    for example, your taxonomy name is “my_custom_taxonomy”, your permalink should be: /%my_custom_taxonomy%/%postname%/

    The hierarchial taxonomy fix doesn’t support %category%.
    %category% use wordpress default code.

    If use %category%, please remove check parent category from your post.

    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?

    Thanks feedback.
    Please show me register_post_type and register_taxonomy setting code.

    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 );
    }
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘3rd level custom taxonomy not included in URL’ is closed to new replies.