• I am getting an error when I try to use get_post_type_labels :
    Cannot use object of type stdClass as array in /wp-includes/post.php on line 969

    this is the whole command I’m using that causes the error
    get_post_type_labels(get_post_type_object(get_post_type()));

    I have to use this to get the singular name of the custom post type

    $ptob = get_post_type_object(get_post_type());
    $name = $ptob->labels->singular_name;

    have I declared my custom post type wrongly?
    here’s how I am declaring it:

    $post_labels = array(
        'name' => __('Menu', 'fwe'),
        'singular_name' => __('Menu Item', 'fwe'),
        'add_new' => __('Add New Item', 'fwe'),
        'add_new_item' => __('Add New Item','fwe'),
        'edit_item' => __('Edit Menu Item','fwe'),
        'new_item' => __('New Item','fwe'),
        'view_item' => __('View Item','fwe'),
        'search_items' => __('Search Menu Items','fwe'),
        'not_found' =>  __('No menu items found','fwe'),
        'not_found_in_trash' => __('No menu items found in Trash','fwe'),
        'parent_item_colon' => ''
      );
      $args = array(
        'labels' => $post_labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'menu', 'with_front' => false ),
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => 2,
        'menu_icon' => $fw_imgurl.'chop-sticks.png',
        'supports' => array('title','editor','thumbnail')
      );
    register_post_type('fwe_menu',$args);

    I see lots of tutorials out there but they’re all slightly different with regards to declaring the post type, is it me or wordpress that is causing the error?

  • The topic ‘error when trying to use get_post_type_labels on custom post type’ is closed to new replies.