1

I'm getting the following warning in my WP admin custom posts listings page (wp-admin/edit.php?post_type=video)

Warning: Illegal offset type in isset or empty in wp-includes/post.php on line 817

I'm running WordPress v3.1.3 (latest). Line 817 is in the function get_post_type_object() . A search finds me these threads:

These mention some different potential causes - e.g. it might be https://core.trac.wordpress.org/ticket/12704 - but that's now fixed (I'm running v3.1.3) - and the final post in one reads:

Basically, you have a plugin registering a post type incorrectly, and then core complains. It isn't a bug in core best I can tell.

I do have a plugin (my own) registering a post type, but I think it's doing it correctly.

Here's the code. (Note that I was originally calling these "video" posts but later renamed the front-end description to "Training Module", but left the original post-type name).

function video_register() {
    $labels = array(
        'name' => _x('Modules', 'post type general name'),
        'singular_name' => _x('Training Module', 'post type singular name'),
        'add_new' => _x('Add New Module', 'video item'),
        'add_new_item' => __('Add New Training Module'),
        'edit_item' => __('Edit Training Module'),
        'new_item' => __('New Training Module'),
        'view_item' => __('View Training Module'),
        'search_items' => __('Search Training Modules'),
        'not_found' =>  __('No Training Modules found'),
        'not_found_in_trash' => __('No Training Modules found in Trash'),
        'parent_item_colon' => ''
    );
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'has_archive' => 'video',
        'menu_icon' => 'video16x16.png',
        'rewrite' => array('slug'=>'training','with_front'=>false),
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => '15',
        'supports' => array('title','author','editor','custom-fields','revisions','comments','trackbacks'),
        'taxonomies' => array('category', 'post_tag')
      );
    register_post_type( 'video' , $args );
}
add_action('init', 'video_register');

Is there a problem there? Why am I seeing the warning?

3
  • I don't get the same error when I add that custom post type registration in my 3.1.3 test install. It would help if you were able to get a full stack trace of this error, so you don't only see the function that got the error, but also what functions called it and with what parameters. Do you know how to get this? (Use @Jan when you reply in a comment and I get a notification)
    – Jan Fabry
    Commented Jun 2, 2011 at 8:47
  • @Jan: If there's a WordPress specific stack trace, I don't know how to generate that - can you tell me how? This is on a shared hosting so might be difficult to get an OS level stack trace if that's what you're talking about. Any other ideas - is there a PHP flag I can set somewhere in the local runtime environment to force debug output that would be useful?
    – AMcDermott
    Commented Jun 3, 2011 at 3:13
  • Some tips on how to get a stack trace: Getting a stack trace when an error occurs?
    – Jan Fabry
    Commented Jun 4, 2011 at 12:30

2 Answers 2

1

I had the same Error. It occured because I requested a post-type that didn't existed.

add_filter( 'pre_get_posts', 'my_get_posts' );

//events don't exists
function my_get_posts( $query ) {
    $query->set( 'post_type', array( 'post', 'page', 'events' ) );
    return $query;
}
0

I had this same issue and thanks to the clues above, how I resolved it.

The commented out line was causing the error messages and the non-commented line is what I changed it to and resolved warning.

/*$query->set( 'post_type', array ( 'product' ) );*/
$query->set( 'post_type', 'product' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.