Advertisement
mogaj

null categories

Jun 24th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. function categoryChecklist( $child_of, $selected_cats )
  2.     {
  3.         $walker = new Walker_Category_Checklist;
  4.         $child_of = (int) $child_of;
  5.        
  6.         $args = array();
  7.         $args['selected_cats'] = $selected_cats;
  8.         $args['popular_cats'] = array();
  9.         //$categories = get_categories( "child_of=$child_of&hierarchical=0&hide_empty=0" );
  10.         $categories = get_categories( "child_of=$child_of&hierarchical=0&hide_empty=0" );
  11.        
  12.         $checked_categories = array();
  13.         for ( $i = 0; isset($categories[$i]); $i++ ) {
  14.             if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) {
  15.                 $checked_categories[] = $categories[$i];
  16.                 unset($categories[$i]);
  17.             }
  18.         }
  19.  
  20.         $null_categories = array();
  21.         for ( $i = 0; isset($categories[$i]); $i++ ) {
  22.             if ( in_array($categories[$i]->count, $args['']) ) {
  23.                 $null_categories[] = $categories[$i];
  24.                 unset($categories[$i]);
  25.             }
  26.         }
  27.  
  28.         // // Put checked cats on top
  29.         // echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
  30.         // // Then the rest of them
  31.         // echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
  32.         echo call_user_func_array(array(&$walker, 'walk'), array($null_categories, 0, $args));
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement