[wp-trac] [WordPress Trac] #41867: wp_list_categories throws SQL error if list is empty

WordPress Trac noreply at wordpress.org
Wed Sep 13 08:05:51 UTC 2017


#41867: wp_list_categories throws SQL error if list is empty
--------------------------+-----------------------------
 Reporter:  firebird75    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:  4.8.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 If via the args, we exclude the only category available in the list, then
 the SQL query will end up wrongly formated (empty : IN() statement).

 See full query here :

 {{{
 SELECT object_id, term_taxonomy_id FROM wp_term_relationships INNER JOIN
 wp_posts ON object_id = ID WHERE term_taxonomy_id IN () AND post_type IN
 ('post') AND post_status = 'publish';
 }}}


 Sample php code :
 {{{#!php
 <?php
 $args = array('taxonomy' => 'category',
               'child_of' => $queried_object->category_parent,
               'depth' => 1,
               'exclude' => $queried_object->cat_ID,
               'echo' => 0,
               'hierarchical' => true,
               'hide_empty' => false,
               'show_count' => 1,
               'title_li' => '');
 echo wp_list_categories($args);
 }}}

 The solution would be to check if there are other categories to be
 displayed and if not, then just return the empty result.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41867>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list