Why do I get a 404 page for setting ‘keywords/sub-keyword’ in the slug rewrite below?

function keyword_pages_init() {
    $args = array(
      'label' => 'Keyword Pages',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'page',
        'hierarchical' => false,
        'rewrite' => array('slug' => 'keywords/sub-keyword'),
        'query_var' => true,
        'menu_icon' => 'dashicons-admin-page',
        'supports' => array(
            'title',
            'editor',
            'excerpt',
            'revisions',
            'thumbnail',
            'author',
            'page-attributes',
            )
        );
    register_post_type( 'keyword-page', $args );
}
add_action( 'init', 'keyword_pages_init' );

Any ideas?

Also, how can I make the sub-keyword dynamic? eg:

'rewrite' => array('slug' => 'keywords/[a-z]'),

Is this possible?

Read more here: Custom post type – how to make slug rewrite dynamic?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: