0

I am trying to create custom taxonomy for my custom post. But when i am trying to add new category, a notice like "notice trying to get property of non-object in...." is showing. Here is the code for custom post

  function newsbox_post() {
    register_post_type( 'newsbox-post',
    array(
        'label'               => __( 'Newsbox Post', 'text_domain' ),
        'labels' => array(
            'name' => __( 'Newsbox Posts' ),
            'singular_name' => __( 'Newsbox Post' ),
            'menu_name'    => __( ' Newsbox Post', 'text_domain' ),
            'parent_item_colon'   => __( 'Parent  Newsbox post:', 'text_domain' ),
            'all_items'           => __( 'All  Newsbox post', 'text_domain' ),
            'view_item'           => __( 'View  Newsbox post', 'text_domain' ),
            'add_new_item'        => __( 'Add New  post', 'text_domain' ),
            'add_new'             => __( 'New post', 'text_domain' ),
            'edit_item'           => __( 'Edit post', 'text_domain' ),
            'update_item'         => __( 'Update post', 'text_domain' ),
            'search_items'        => __( 'Search post', 'text_domain' ),
            'not_found'           => __( 'No post found', 'text_domain' ),
            'not_found_in_trash'  => __( 'No post found in Trash', 'text_domain' )
        ),
        'public' => true,
        'rewrite' => array('slug' => 'Newsbox-post'),
        'description'         => __( 'Enter recent to your newsbox', 'text_domain' ),
        'supports'            => array( 'title', 'editor', 'page-attributes' ),
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => false,
        'show_in_admin_bar'   => true,
        'can_export'          => false,
        'has_archive'         => false,
        'exclude_from_search' => true,
        'publicly_queryable'  => true,
        'capability_type'     => 'post'
        )
  );
 }

add_action( 'init', 'newsbox_post' );

and here is the code for custom taxonomy

 add_action( 'init', 'newsbox_post_category_taxonomy', 0 );

 function newsbox_post_category_taxonomy() {
 $labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Categories', 'taxonomy singular name' ),
'search_items' =>  __( 'Search Category' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ), 
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Categories Name' ),
'menu_name' => __( 'Categories' ),
 );     



  register_taxonomy('Categories',array('newsbox-post'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true

  ));

  }

Please tell me the solution. Thanks.

Bir
  • 794
  • 1
  • 15
  • 31
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – brasofilo Sep 01 '14 at 15:51

1 Answers1

1

Your problem relates to grammar. There are two problems off the back with your code

  • Never use camelcase in custom taxonomy names or in custom post type names.

  • Never use hypens (-), and for that matter any special character, in custom post type names or custom taxonomy names. If you have to separate names/words in a name, only make use of an underscore (_)

Categories should be categories for your taxonomy name and newsbox-post should be newsbox_post for your custom post type name

EDIT

Properly formatted your code and made relevant changes. Tested and works

add_action( 'init', 'combined_registration' );

function combined_registration() {
    $labels = array(
        'name' => _x( 'Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Categories', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Category' ),
        'all_items' => __( 'All Categories' ),
        'parent_item' => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item' => __( 'Edit Category' ), 
        'update_item' => __( 'Update Category' ),
        'add_new_item' => __( 'Add New Category' ),
        'new_item_name' => __( 'New Categories Name' ),
        'menu_name' => __( 'Categories' ),
    );     

    register_taxonomy('categories',array('newsbox_post'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true
        )
    );

    register_post_type( 'newsbox_post',
        array(
            'label'                 => __( 'Newsbox Post', 'text_domain' ),
            'labels'                => array(
            'name'                  => __( 'Newsbox Posts' ),
            'singular_name'         => __( 'Newsbox Post' ),
            'menu_name'             => __( ' Newsbox Post', 'text_domain' ),
            'parent_item_colon'     => __( 'Parent  Newsbox post:', 'text_domain' ),
            'all_items'             => __( 'All  Newsbox post', 'text_domain' ),
            'view_item'             => __( 'View  Newsbox post', 'text_domain' ),
            'add_new_item'          => __( 'Add New  post', 'text_domain' ),
            'add_new'               => __( 'New post', 'text_domain' ),
            'edit_item'             => __( 'Edit post', 'text_domain' ),
            'update_item'           => __( 'Update post', 'text_domain' ),
            'search_items'          => __( 'Search post', 'text_domain' ),
            'not_found'             => __( 'No post found', 'text_domain' ),
            'not_found_in_trash'    => __( 'No post found in Trash', 'text_domain' )
            ),
            'public'                => true,
            'rewrite'               => array('slug' => 'newsbox-post'),
            'description'           => __( 'Enter recent to your newsbox', 'text_domain' ),
            'supports'              => array( 'title', 'editor', 'page-attributes' ),
            'show_ui'               => true,
            'show_in_menu'          => true,
            'show_in_nav_menus'     => false,
            'show_in_admin_bar'     => true,
            'can_export'            => false,
            'has_archive'           => false,
            'exclude_from_search'   => true,
            'publicly_queryable'    => true,
            'capability_type'       => 'post'
        )
    );
}
Pieter Goosen
  • 9,768
  • 5
  • 35
  • 55
  • Change but same result @Piter Goosen – Bir Sep 01 '14 at 16:02
  • Problem solve. But i am facing another problem when try to access feature image. You can check here https://dl.dropboxusercontent.com/u/168659703/Screenshot_1.png here is the code `$newsbox_post_img_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '', false, '' );` – Bir Sep 01 '14 at 16:33
  • You should accept my answer then. As for the other problem you are facing, it is out of scope for this question, you should start a new question :-). Thank you – Pieter Goosen Sep 01 '14 at 16:42