On saving Post My permalink is updated and category is removed automatically which cause the 404

Question

Hi to all I am facing an issue with WordPress
On saving my custom post My permalink is updated and the category is removed automatically from the url which cause the 404 for the post
here is my custom postcode

/** News Custom Post **/


add_action( 'init', 'tm_news_cpt' );



function tm_news_cpt() {



$labels = array(

'name' => _x( 'News', 'text_domain' ),

'singular_name' => _x( 'News', 'text_domain' ),

'add_new' => _x( 'Add New', 'text_domain' ),

'add_new_item' => _x( 'Add New News', 'text_domain' ),

'edit_item' => _x( 'Edit News', 'text_domain' ),

'new_item' => _x( 'New News', 'text_domain' ),

'view_item' => _x( 'View News', 'text_domain' ),

'search_items' => _x( 'Search News', 'text_domain' ),

'not_found' => _x( 'No News found', 'text_domain' ),

'not_found_in_trash' => _x( 'No News found in Trash', 'text_domain' ),

'parent_item_colon' => _x( 'Parent News:', 'text_domain' ),

'menu_name' => _x( 'News', 'text_domain' ),

);



$args = array(

'label'               => __( 'News', 'text_domain' ),

'description'         => __( 'Post Type Description', 'text_domain' ),

'labels'              => $labels,

'supports'            => array('title','text','editor','thumbnail','author', 'page-attributes', 'custom-fields','comments' ),

'hierarchical'        => false,

'rewrite'             => array('slug' => 'news/%news_cat%'),

'public'              => true,

'show_ui'             => true,

'show_in_menu'        => true,

'show_in_nav_menus'   => true,

'show_in_admin_bar'   => true,

'menu_position'       => 6,

'menu_icon'           => 'dashicons-admin-post',

'can_export'          => true,

'has_archive'         => true,

'exclude_from_search' => false,

'publicly_queryable'  => true,

);

register_post_type( 'news', $args );

}



function tm_news_taxonomy() {  

    register_taxonomy(  

        'news_cat', 

        'news',

        array(  

            'hierarchical' => true, 

            'show_admin_column'=>true, 

            'label' => 'Categories',

            'query_var' => true,

            'rewrite' => array(

                'slug' => 'news_cat',

                'with_front' => false

            )

        )  

    );  

}  

add_action( 'init', 'tm_news_taxonomy');

on save, the post is just updating a meta value.

This is how it looks before update

See my permalink before update

so before the update, my permalink is like news/destination/title-of-post

Where the destination is the category name

And After update it look like this

Afetr update my Image

Due to this change in permalink page goes to 404 on view as well as on front end

0
Jagdish Sharma 1 month 2021-10-22T21:21:21-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse