[wp-trac] [WordPress Trac] #15449: Notice generated in get_category_link function with a category id that does not exist

WordPress Trac wp-trac at lists.automattic.com
Thu Nov 18 17:50:28 UTC 2010


#15449: Notice generated in get_category_link function with a category id that does
not exist
------------------------------+---------------------------------------------
 Reporter:  kapilchugh        |       Owner:                           
     Type:  defect (bug)      |      Status:  new                      
 Priority:  normal            |   Milestone:  3.1                      
Component:  Warnings/Notices  |     Version:  3.0.1                    
 Severity:  normal            |    Keywords:  get_category_link, notice
------------------------------+---------------------------------------------

Comment(by kapilchugh):

 I did this thing

 {{{
 <?php
 $cat_id = '';
 $cat_id = get_option('kp_sidebar_cat2');
 $cat_name = get_cat_name( $cat_id );
 $cat_link = get_category_link( $cat_id );
 ?>
 }}}
 Somehow i was getting value of $cat_id 4 but there was no such category
 with this id and because of this i was getting this notice.

 {{{
 Notice: Trying to get property of non-object in C:\xampp\htdocs\wordpress
 \wp-includes\category-template.php on line 28
 }}}

 Reason is :-

 When i checked i found et_category_link() calls get_category() function
 and 25th line of category-template.php is this one
 {{{
 $category = &get_category( $category_id );
 }}}
 and $category was returning NULL.

 When i changed the condition on 26th line of category-template.php with
 this condition
 {{{
 if ( is_null($category) || is_wp_error( $category ) )
 }}}
 '''
 After that everything was right.I think wp_error is not handling NULL
 statement.'''

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15449#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list