Support Forum
Support › General › "Cannot use empty array elements in arrays" after adding code from GeneratorResolved
Hi
just wanted to try the Taxonomy Generator for creating a custom category "PagesCat" for my pages.
After I have filled the fields of the Generator, copied the code and added it (without the opening php-tag) to my child-themes function.php, the following error occurred:
"Your PHP code changes were rolled back due to an error on line 47 of file wp-content/themes/generatepress_child/functions.php. Please fix and try saving again.
Cannot use empty array elements in arrays"
What did I do wrong here?
The functions.php only contains the generated code, so I hope you don't mind me pasting it here:
<?php
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/
add_action( 'init', 'mb_register_taxonomy_for_pages' );
function mb_register_taxonomy_for_pages() {
$args = [
'label' => esc_html__( 'PagesCat', 'mb-tax-for-pages' ),
'labels' => [
'menu_name' => esc_html__( 'PagesCat', 'mb-tax-for-pages' ),
'all_items' => esc_html__( 'All PagesCat', 'mb-tax-for-pages' ),
'edit_item' => esc_html__( 'Edit PagesCat', 'mb-tax-for-pages' ),
'view_item' => esc_html__( 'View PagesCat', 'mb-tax-for-pages' ),
'update_item' => esc_html__( 'Update PagesCat', 'mb-tax-for-pages' ),
'add_new_item' => esc_html__( 'Add new PagesCat', 'mb-tax-for-pages' ),
'new_item' => esc_html__( 'New PagesCat', 'mb-tax-for-pages' ),
'parent_item' => esc_html__( 'Parent PagesCat', 'mb-tax-for-pages' ),
'parent_item_colon' => esc_html__( 'Parent PagesCat', 'mb-tax-for-pages' ),
'search_items' => esc_html__( 'Search PagesCat', 'mb-tax-for-pages' ),
'popular_items' => esc_html__( 'Popular PagesCat', 'mb-tax-for-pages' ),
'separate_items_with_commas' => esc_html__( 'Separate PagesCat with commas', 'mb-tax-for-pages' ),
'add_or_remove_items' => esc_html__( 'Add or remove PagesCat', 'mb-tax-for-pages' ),
'choose_from_most_used' => esc_html__( 'Choose most used PagesCat', 'mb-tax-for-pages' ),
'not_found' => esc_html__( 'No PagesCat found', 'mb-tax-for-pages' ),
'name' => esc_html__( 'PagesCat', 'mb-tax-for-pages' ),
'singular_name' => esc_html__( 'PagesCat', 'mb-tax-for-pages' ),
],
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_tagcloud' => true,
'show_in_quick_edit' => true,
'show_admin_column' => false,
'show_in_rest' => true,
'hierarchical' => false,
'query_var' => true,
'sort' => false,
'rewrite_no_front' => false,
'rewrite_hierarchical' => false,
'rewrite' => true
];
register_taxonomy( 'pagescat', [ , 'page' ], $args );
}
Thank you in advance and kind regards,
Sascha
Well, I think I found the problem's origin:
When I chose "Pages" and disable "Posts" in the Generator Post-Types-Tab, the syntax of the register-action (or array) seems broken. This is the output:
register_taxonomy( 'pagescat', [ ,'page' ], $args );
but instead it should be
register_taxonomy( 'pagescat', ['page' ], $args );
Am I correct? Please note that I'm not a developer …
Maybe a bug in the Taxonomie Generator?
Thank you in advance and kind regards,
Sascha
Hi,
You are correct. I've also escalated this issue to the development team to fix it in future updates.