Hi there
I am trying to add my second custom post type to Functions.php and have copied exactly the same code as works for the first one, changing the relevant words to relate to the new one, and pasted it below. When I try to access the dashboard after uploading, I continually receive this error message:
Fatal error: Cannot redeclare codex_custom_init() (previously declared in /home/content/98/4487498/html/wp-content/themes/arthemia/functions.php:6) in /home/content/98/4487498/html/wp-content/themes/arthemia/functions.php on line 124
Any ideas?
Thanks
Jacob Chappell
Member
Posted 1 year ago #
Looks to me like you're re-using a function name (which you can't do). Every function must be unique and so you need to use some prefixes or suffixes to avoid collisions. For example, instead of using codex_custom_init() for your second post type, use something like codex_custom_init_two()
Troy Chaplin
Member
Posted 1 year ago #
Alternatively, you can have multiple custom post type within the same function like this:
<?php
function codex_custom_init() {
// FIRST POST TYPE
register_post_type('post-type-one', array(
// add info here
) );
// SECOND POST TYPE
register_post_type('post-type-two', array(
// add info here
) );
// IMPORTANT: Remember this line!
flush_rewrite_rules( false );
}
// Initialise custom post type
add_action('init', 'codex_custom_init', 1);
?>
Zukes
Member
Posted 10 months ago #
Thank you guys, really helpfull