• Hello everyone

    I managed to create a custom post type by editing functions.php but cannot add any category names to the custom post type by way of adding the following line in (as shown at https://www.wpbeginner.com/wp-tutorials/how-to-add-categories-to-a-custom-post-type-in-wordpress/):

    'taxonomies' => array('topics', 'category' ),

    I inserted the line above into the array in register_post_type with no luck:

    
    register_post_type('news',
     array(
      'labels' => array(
      'name' => __('Investment'),
      'public' => true,
      'has_archive' => true,
      'supports' => array('title', 'editor', 'thumbnail'),
     'taxonomies' => array('topics', 'category' ),
     )
    );
    

    Did I insert the line into the wrong location or does it require more scripting? Either way, some advice would be appreciated.

    • This topic was modified 6 years, 3 months ago by eadwig.
Viewing 1 replies (of 1 total)
  • It looks like there’s an error around your ‘labels’ array. You’re opening two brackets (after ‘array’ and before ‘Investment’, but only closing one of those brackets (after ‘Investment’. And do you really want to label ‘news’ as ‘Investment’?

    Try this:

    register_post_type('news',
     array(
      'labels' => array('name' => 'Investment'), 
      'public' => true,
      'has_archive' => true,
      'supports' => array('title', 'editor', 'thumbnail'),
     	'taxonomies' => array('topics', 'category' ),
     )
    );
Viewing 1 replies (of 1 total)
  • The topic ‘Cannot add category names to custom post types’ is closed to new replies.