FAQ Post Type With Groups
Registers an "FAQs" post type (question as the title, answer as the content) with an FAQ Group taxonomy, for help centers and FAQ pages.
Opens WPIDE on
Code
// Names used in labels and URLs: edit to suit.
$wpide_type = array(
'name' => 'faq', // Internal name: lowercase, max 20 characters, never change it once you have content.
'singular' => 'FAQ',
'plural' => 'FAQs',
'slug' => 'faq',
);
add_action( 'init', function () use ( $wpide_type ) {
$s = $wpide_type['singular'];
$p = $wpide_type['plural'];
register_post_type( $wpide_type['name'], array(
'labels' => array(
'name' => $p,
'singular_name' => $s,
'menu_name' => $p,
'add_new_item' => "Add New $s",
'edit_item' => "Edit $s",
'new_item' => "New $s",
'view_item' => "View $s",
'view_items' => "View $p",
'all_items' => "All $p",
'search_items' => "Search $p",
'not_found' => 'Nothing found.',
'not_found_in_trash' => 'Nothing found in Trash.',
'archives' => "$s Archives",
'attributes' => "$s Attributes",
'insert_into_item' => "Insert into $s",
'uploaded_to_this_item' => "Uploaded to this $s",
'item_published' => "$s published.",
'item_updated' => "$s updated.",
),
'public' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'has_archive' => false,
'rewrite' => false,
'show_in_rest' => true,
'menu_icon' => 'dashicons-editor-help',
'menu_position' => 24,
'supports' => array( 'title', 'editor', 'page-attributes' ),
) );
register_taxonomy( 'faq_group', $wpide_type['name'], array(
'labels' => array(
'name' => 'FAQ Groups',
'singular_name' => 'FAQ Group',
'menu_name' => 'FAQ Groups',
'all_items' => 'All FAQ Groups',
'edit_item' => 'Edit FAQ Group',
'view_item' => 'View FAQ Group',
'update_item' => 'Update FAQ Group',
'add_new_item' => 'Add New FAQ Group',
'new_item_name' => 'New FAQ Group Name',
'search_items' => 'Search FAQ Groups',
'not_found' => 'No faq groups found.',
'parent_item' => 'Parent FAQ Group',
),
'hierarchical' => true,
'public' => false,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
) );
} );
Notes
FAQs have no single pages; list them with a shortcode or a Query Loop block.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.