Title: Custom post types : &#8220;Undefined offset: 0&#8221; error
Last modified: July 15, 2019

---

# Custom post types : “Undefined offset: 0” error

 *  [muttznutz](https://wordpress.org/support/users/muttznutz/)
 * (@muttznutz)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/custom-post-types-undefined-offset-0-error/)
 * Hi
    This plugin doesn’t seem to be actively supported any more, so I’ll post 
   a bit of code (that works for me). Since the last update, I get a pair of PHP
   error message under certain circiumstances :
 *     ```
       Undefined offset: 0 in [...]/plugins/extended-categories-widget/4.2/class/avh-ec.core.php on line 140
       Trying to get property of non-object in [...]/extended-categories-widget/4.2/class/avh-ec.core.php on line 140
       ```
   
 * These seem to occur when the post is not assigned to a category. WordPress assigns
   normal post types to the “Uncategorised” category, but custom post types can 
   be unassigned – particularly when saved as drafts.
    The code in question is in
   the avh-ec.core.php script, at the lines :
 *     ```
       	if (is_single()) {
       			$post_cats                = get_the_category();
       			$args['current_category'] = $post_cats[0]->term_id;
       		}
       ```
   
 * Adding a test to check for the existence of a post category resolves this (apparently,
   the plugin code only assigns a css class, so nothing should be broken).
 *     ```
       	if (is_single()) {
       		$post_cats                = get_the_category();
       		if (!empty( $post_cats ) ) {
       			$args['current_category'] = $post_cats[0]->term_id;
       			}
       		}
       ```
   
 * If the author does reissue this (really useful) plugin, then I hope he’ll take
   this on board.

Viewing 1 replies (of 1 total)

 *  [aaronwordpress](https://wordpress.org/support/users/aaronwordpress/)
 * (@aaronwordpress)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/custom-post-types-undefined-offset-0-error/#post-11925529)
 * [@muttznutz](https://wordpress.org/support/users/muttznutz/) [@petervanderdoes](https://wordpress.org/support/users/petervanderdoes/)
   Thank you for sharing your fix. I agree the author created a great plugin, which
   we sadly miss and his valuable updates.

Viewing 1 replies (of 1 total)

The topic ‘Custom post types : “Undefined offset: 0” error’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/extended-categories-widget.svg)
 * [AVH Extended Categories Widgets](https://wordpress.org/plugins/extended-categories-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/extended-categories-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/extended-categories-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/extended-categories-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/extended-categories-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/extended-categories-widget/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [aaronwordpress](https://wordpress.org/support/users/aaronwordpress/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/custom-post-types-undefined-offset-0-error/#post-11925529)
 * Status: not resolved