wordpress permalink set while create a custom post using code "register_post_type"

StackOverflow https://stackoverflow.com/questions/23654063

  •  22-07-2023
  •  | 
  •  

Question

I have tried with set permalink when create a custom post: permalink structure "custom_post_name/year/month/post-id".

i have tried some following code but not work

add_action( 'init', 'video' );

function video() {
        register_post_type( 'video',
            array(
                'labels' => array(
                    'name' => 'Video',
                    'singular_name' => 'video',
                    'add_new' => 'Add New',
                    'add_new_item' => 'Add New',
                    'edit' => 'Edit',
                    'edit_item' => 'Edit',
                    'new_item' => 'New',
                    'view' => 'View',
                    'view_item' => 'View',
                    'search_items' => 'Search',
                    'not_found' => 'No Video found',
                    'not_found_in_trash' => 'No Videos found in Trash',
                    'parent' => 'Parent'
                ),

                'public' => true,
                'menu_position' => 15,
                'supports' => array( 'title', 'editor' ),
                'rewrite'=>array('slug'=>'/video/%year%/%monthnum%/%post_id%/'),
                'has_archive' => true
            )
        );
    }
Was it helpful?

Solution

'rewrite' => array('slug' => '/video/%year%/%monthnum%/%post_id%/', 'with_front' => FALSE) This will solve your problem, and don't forget to goto [Settings -> Permalinks] and Save the changes for taking effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top