plugins – Custom Post Type with Custom Taxonomy as Category post_type_link, after this code only the home page and the taxonomy page are opened

Question

// Register Custom Taxonomy
function portfolio_taxonomy() {

    $labels = array(
        'name'                       => _x( 'Labels', 'Taxonomy General Name', 'imagewize_portfolio_plugin' ),
        'singular_name'              => _x( 'Label', 'Taxonomy Singular Name', 'imagewize_portfolio_plugin' ),
        'menu_name'                  => __( 'Labels', 'imagewize_portfolio_plugin' ),
        'all_items'                  => __( 'All Items', 'imagewize_portfolio_plugin' ),
        'parent_item'                => __( 'Parent Item', 'imagewize_portfolio_plugin' ),
        'parent_item_colon'          => __( 'Parent Item:', 'imagewize_portfolio_plugin' ),
        'new_item_name'              => __( 'New Item Name', 'imagewize_portfolio_plugin' ),
        'add_new_item'               => __( 'Add New Item', 'imagewize_portfolio_plugin' ),
        'edit_item'                  => __( 'Edit Item', 'imagewize_portfolio_plugin' ),
        'update_item'                => __( 'Update Item', 'imagewize_portfolio_plugin' ),
        'separate_items_with_commas' => __( 'Separate items with commas', 'imagewize_portfolio_plugin' ),
        'search_items'               => __( 'Search Items', 'imagewize_portfolio_plugin' ),
        'add_or_remove_items'        => __( 'Add or remove items', 'imagewize_portfolio_plugin' ),
        'choose_from_most_used'      => __( 'Choose from the most used items', 'imagewize_portfolio_plugin' ),
        'not_found'                  => __( 'Not Found', 'imagewize_portfolio_plugin' ),
    );
    $rewrite = array(
        'slug'                       => 'label',
        'with_front'                 => true,
        'hierarchical'               => true,
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
        'rewrite'                    => $rewrite,
    );
    register_taxonomy( 'label', array( 'Img_portfolio_cpt' ), $args );

}

// Hook into the 'init' action
add_action( 'init', 'portfolio_taxonomy', 0 );



if ( ! function_exists('img_portfolio_cpt') ) {

// Register Custom Post Type
function img_portfolio_cpt() {

    $labels = array(
        'name'                => _x( 'Portfolio Items', 'Post Type General Name', 'imagewize_portfolio_plugin' ),
        'singular_name'       => _x( 'Portfolio', 'Post Type Singular Name', 'imagewize_portfolio_plugin' ),
        'menu_name'           => __( 'Portfolio', 'imagewize_portfolio_plugin' ),
        'parent_item_colon'   => __( 'Parent Item:', 'imagewize_portfolio_plugin' ),
        'all_items'           => __( 'All Items', 'imagewize_portfolio_plugin' ),
        'view_item'           => __( 'View Item', 'imagewize_portfolio_plugin' ),
        'add_new_item'        => __( 'Add New Item', 'imagewize_portfolio_plugin' ),
        'add_new'             => __( 'Add New', 'imagewize_portfolio_plugin' ),
        'edit_item'           => __( 'Edit Item', 'imagewize_portfolio_plugin' ),
        'update_item'         => __( 'Update Item', 'imagewize_portfolio_plugin' ),
        'search_items'        => __( 'Search Item', 'imagewize_portfolio_plugin' ),
        'not_found'           => __( 'Not found', 'imagewize_portfolio_plugin' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'imagewize_portfolio_plugin' ),
    );
    $rewrite = array(
        'slug'                => '%label%',
        'with_front'          => true,
        'pages'               => true,
        'feeds'               => true,
    );
    $args = array(
        'label'               => __( 'Img_portfolio_cpt', 'imagewize_portfolio_plugin' ),
        'description'         => __( 'Imagewize Portfolio', 'imagewize_portfolio_plugin' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'author', 'thumbnail', ),
        'taxonomies'          => array( 'label' ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'menu_icon'           => 'dashicons-portfolio',
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'rewrite'             => $rewrite,
        'capability_type'     => 'page',
    );
    register_post_type( 'Img_portfolio_cpt', $args );

}

// Hook into the 'init' action
add_action( 'init', 'img_portfolio_cpt', 0 );

}

add_filter(‘post_type_link’, ‘portfolio_permalink_structure’, 10, 4);
function portfolio_permalink_structure($post_link, $post, $leavename, $sample)
{
if ( false !== strpos( $post_link, ‘%label%’ ) ) {
$label_term = get_the_terms( $post->ID, ‘label’ );
$post_link = str_replace( ‘%label%’, array_pop( $label_term )->slug, $post_link );
}
return $post_link;
}

after this code only the home page and the taxonomy page are opened
what a solution can be found

0
Sardor 3 weeks 2021-12-28T00:29:12-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse