i use below piece of code to register a new post type in function.php
. but the post type won’t register. and when i go to the url domain.com/wp-admin/edit.php?post_type=transaction
, the message "Invalid post type" is shown.
add_action( 'init', 'transaction' );
function transaction() {
$labels = array(
'name' => _x( 'Transactions' ),
'singular_name' => _x( 'Transaction' ),
'add_new_item' => __( 'Add New Transaction' ),
'edit_item' => __( 'Edit Transaction' ),
'new_item' => __( 'New Transaction' ),
'all_items' => __( 'All Transaction' ),
'view_item' => __( 'View Transaction' ),
'search_items' => __( 'Search Transaction' ),
'not_found' => __( 'No Transaction found' ),
'not_found_in_trash' => __( 'No Transaction found in the Trash' ),
'menu_name' => 'Transaction'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'revisions' ),
'show_in_rest' => true,
'show_in_menu' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
);
register_post_type( 'transaction', $args );
}
i have tried changing menu_position
but it didn’t work. activating the debugger won’t show what the problem is either.
p.s. i’m trying to build a theme from scratch; when i use this code in a child theme of any theme (i.e Astra theme) it works just fine!
thanks in advance!