• I installed this plugin and tried to change the permalink structure of a custom post type.
    /%injury_category%/%postname%/
    is the code i used in permalink settings. But I am getting 404 error. ‘injury_category’ is the custom taxonomy name.

    function injury_post_type() {
    
             $labels = array(
                    'name' => __('Injury','reo_theme'),
                    'singular_name' => __('Injury','reo_theme'),
                    'add_new' => __('Add Injury','reo_theme'),
                    'add_new_item' => __('Add New Injury','reo_theme'),
                    'edit_item' => __('Edit Injury','reo_theme'),
                    'new_item' => __('New Injury','reo_theme'),
                    'view_item' => __('Preview Injury','reo_theme'),
                    'not_found' => __('No Injurys Found','reo_theme'),
                    'not_found_in_trash' => __('No Injurys Found In Trash','reo_theme'),
                    );
    
             $args = array(
                   'labels' => $labels,
                   'public' => true,
                   'publicly_queryable' => true,
                   'show_ui' => true,
                   'query_var' => true,
                   'rewrite' => true,
                   'capability_type' => 'post',
                   'hierarchical' => false,
                   'menu_position' => 100,
                   'supports' => array(
                                 'title',
    							 'editor',
    							 'thumbnail'
                                 )
                   );
    
             register_post_type(__( 'injury','reo_theme'), $args);
    }
    //END: injury_post_type
    
    // injury_messages
    function injury_messages($messages)
    {
        $messages[__( 'injury' )] =
            array(
                0 => '',
                1 => sprintf(__('Injury Updated.','reo_theme'), esc_url(get_permalink($post_ID))),
                2 => __('Custom Field Updated.','reo_theme'),
                3 => __('Custom Field Deleted.','reo_theme'),
                4 => __('Injury Updated.','reo_theme'),
                5 => isset($_GET['revision']) ? sprintf( __('Injury Restored To Revision From %s','reo_theme'), wp_post_revision_title((int)$_GET['revision'], false)) : false,
                6 => sprintf(__('Injury Published.','reo_theme'), esc_url(get_permalink($post_ID))),
                7 => __('Injury Saved.','reo_theme'),
                8 => sprintf(__('Injury Submitted.','reo_theme'), esc_url( add_query_arg('preview', 'true', get_permalink($post_ID)))),
                9 => sprintf(__('Injury Scheduled For: <strong>%1$s</strong>.','reo_theme'), date_i18n( __( 'M j, Y @ G:i' ), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
                10 => sprintf(__('Injury Draft Updated.','reo_theme'), esc_url( add_query_arg('preview', 'true', get_permalink($post_ID)))),
            );
        return $messages;
    
    } // END: injury_messages
    
    //Get the thumbnail
    function injury_thumbnail($post_ID) {
        $injury_thumbnail_id = get_post_thumbnail_id($post_ID);
        if ($injury_thumbnail_id) {
            $injury_thumbnail_img = wp_get_attachment_image_src($injury_thumbnail_id, 'featured_preview');
            return $injury_thumbnail_img[0];
        }
    }
    
    //Modify admin columns
    function injury_edit_columns($columns){
            $columns = array(
                "cb" => "<input type=\"checkbox\" />",
                "title" => __('Injury title','reo_theme'),
                "thumb" => __('Preview image','reo_theme'),
            );
    
            return $columns;
    }
    
    //Content for admin columns
    function injury_custom_columns($column){
            global $post;
            switch ($column)
            {
                case "thumb":
                    $injury_thumb = injury_thumbnail($post_ID);
                         if ($injury_thumb) {
                            echo '<img src="' . $injury_thumb . '" width="55" />';
                         }
                break;
            }
    }
    
    add_action( 'init', 'injury_post_type' );
    add_action('admin_menu', 'injury_settings_menu');
    add_filter( 'injury_updated_messages', 'injury_messages' );
    add_filter('manage_reo_injury_posts_columns', 'injury_edit_columns');
    add_action('manage_reo_injury_posts_custom_column', 'injury_custom_columns', 10, 2);
    add_action( 'init', 'create_discog_taxonomies', 0 );
    function create_discog_taxonomies()
    {
      // Add new taxonomy, make it hierarchical (like categories)
      $labels = array(
        'name' => _x( 'Injury Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Injury Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Injury Categories' ),
        'popular_items' => __( 'Popular Injury Categories' ),
        'all_items' => __( 'All Injury Categories' ),
        'parent_item' => __( 'Parent Injury Categories' ),
        'parent_item_colon' => __( 'Parent Injury Category:' ),
        'edit_item' => __( 'Edit Injury Category' ),
        'update_item' => __( 'Update Injury Category' ),
        'add_new_item' => __( 'Add New Injury Category' ),
        'new_item_name' => __( 'New Injury Category Name' ),
      );
      register_taxonomy('injury_category',array('injury'), array(
        'hierarchical' => false,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'injury-category' ),
      ));
    }

    This is the custom post type register code. Please help me to resolve this problem

    Thanks

    https://www.ads-software.com/plugins/wp-permastructure/

  • The topic ‘404 error’ is closed to new replies.