• Simon

    (@simonfricker)


    Hello,

    I have created a created a Custom Post Type called ‘help’ with categories enabled.

    The archive page directs to
    https://www.example.com/help

    All posts in help link like this:
    https://www.example.com/help/post-title/

    Is there a way for the the URL to reflect the post category too eg:
    https://www.example.com/help/category-title/post-title/

    I would also like to set an archive page at the following location:
    https://www.example.com/help/category-title/

    Here is the code from my functions:

    // Register Custom Post Type for Knowledge Base
    function eo_help_post() {
    
    	$labels = array(
    		'name'                => 'Help',
    		'singular_name'       => 'Knowledge base post',
    		'menu_name'           => 'Knowledge Base',
    		'name_admin_bar'      => 'Knowledge Base',
    		'parent_item_colon'   => 'Parent Post:',
    		'all_items'           => 'All Posts',
    		'add_new_item'        => 'Add New Post',
    		'add_new'             => 'Add New',
    		'new_item'            => 'New Post',
    		'edit_item'           => 'Edit Post',
    		'update_item'         => 'Update Post',
    		'view_item'           => 'View Post',
    		'search_items'        => 'Search Pst',
    		'not_found'           => 'Not found',
    		'not_found_in_trash'  => 'Not found in Trash',
    	);
    	$rewrite = array(
    		'slug'                => 'help',
    		'with_front'          => true,
    		'pages'               => true,
    		'feeds'               => false,
    	);
    	$args = array(
    		'label'               => 'Knowledge base post',
    		'description'         => 'Knowledge base posts',
    		'labels'              => $labels,
    		'supports'            => array( 'title', 'editor', 'excerpt', ),
    		'taxonomies'          => array( 'category' ),
    		'hierarchical'        => false,
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'menu_position'       => 5,
    		'menu_icon'           => 'dashicons-info',
    		'show_in_admin_bar'   => false,
    		'show_in_nav_menus'   => false,
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'rewrite'             => $rewrite,
    		'capability_type'     => 'page',
    	);
    	register_post_type( 'eo_help_post', $args );
    
    }
    add_action( 'init', 'eo_help_post', 0 );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom post types and custom category name.’ is closed to new replies.