• Hi,

    Sorry in advance if any of this is basic stuff – I’m learning as I go…

    I’m developing a college site where users can view courses. I want to divide courses into categories, so I’ve tried to set up the custom post type ‘Courses’ and the custom taxonomy ‘Course Category’. Here’s my code from functions.php for that:

    // Registers the extra 'Courses' Menu Item
    add_action( 'init', 'create_courses_post_type' );
    function create_courses_post_type() {
    	register_post_type( 'courses',
    		array(
    			'labels' => array(
    			'name' => __( 'Courses' ),
    			'singular_name' => __( 'Course' )
    			),
    			'public' => true,
    			'supports' => array( 'title', 'editor' ),
    			//Change the menu icon:
    			'menu_icon' => get_bloginfo('template_directory') . '/images/courses16.png',
    		)
    	);
    }
    
    // Adds 'Course Category' taxonomy
    add_action( 'init', 'create_course_kinds' );
    function create_course_kinds() {
     $labels = array(
        'name' => _x( 'Course Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Course Category', 'taxonomy singular name' ),
      );
      register_taxonomy('course_kind','courses',array(
        'hierarchical' => false,
        'labels' => $labels
      ));
    }

    Problem is, when I try to add course categories, in this case ‘health & safety’ in the admin area I get the following 2 errors:

    Warning: Invalid argument supplied for foreach() in /…/development/wp-admin/includes/plugin.php on line 1261

    Warning: Cannot modify header information – headers already sent by (output started at /…/development/wp-admin/includes/plugin.php:1261) in /…/development/wp-includes/class-wp-ajax-response.php on line 129 Health & Safety

    healthy and safehealth-and-safety0]]>

    The line it refers to (wpadmin/includes/plugin.php:1261) is the foreach() within the code below:

    /**
     * Remove a top level admin menu
     *
     * @since 3.1.0
     *
     * @param string $menu_slug The slug of the menu
     * @return array|bool The removed menu on success, False if not found
     */
    function remove_menu_page( $menu_slug ) {
    	global $menu;
    
    	foreach ( $menu as $i => $item ) {
    		if ( $menu_slug == $item[2] ) {
    			unset( $menu[$i] );
    			return $item;
    		}
    	}
    
    	return false;
    }

    I’ve searched the forums & tried removing whitespace as suggested but I think this is a different issue. I’ve also deactivated plugins one at a time and the problem persists. I’ve also been stripping out admin menus I don’t require – could this be why I’m getting the errors?

    Any help would be much appreciated!

Viewing 1 replies (of 1 total)
  • Thread Starter theflyingant

    (@theflyingant)

    In case anyone else stumbles across this I’ve actually just narrowed it down to some code I was using to strip out some comments functionality.

Viewing 1 replies (of 1 total)
  • The topic ‘custom post type & custom taxonomy 'add new' warnings’ is closed to new replies.