Get Categories and orderby

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19837
    cubic
    Participant

      Hi,
      I’m trying to add a menu navigation without child categories with wp_list_categories().
      All is fine but I have a problem with order (orderby).
      If I open the file wppizza-navigation.php, i can see this code :
      echo wp_list_categories( $args );
      I added print_r($args); , and I have :

      Array ( [taxonomy] => wppizza_menu [orderby] => name [show_count] => 0 [pad_counts] => 0 [hierarchical] => 1 [title_li] => [depth] => 0 [exclude] => [child_of] => 0 [show_option_none] => Nothing here [hide_empty] => 1 [echo] => 0 )

      I copied this arguments to make my own function :

      
      function my_nav(){
      $myargs=array ( 
      'taxonomy' => 'wppizza_menu' ,
      'orderby' => 'name' ,
      'show_count' => 0 ,
      'pad_counts' => 0 ,
      'hierarchical' => 1 ,
      'title_li' =>'' ,
      'depth' => 1  ,
      'child_of' => 0 ,
      'show_option_none' => 'Nothing here' ,
      'hide_empty' => 1 ,
      'echo' => 0 ,
      );
      echo wp_list_categories( $myargs );
      }
      

      With your function, the order is right, like in Admin > wppizza > categories, but with my function the order is wrong. I think ‘orderby’ = >’name’ is the problem, so I tried different value, but I can’t find the right. And I searched in the Database to looking for the variable of order. But no result. I don’t understand why the parameter ‘orderby’ => ‘name’ is ok in your function.
      Do you know how can I have the right order with wp_list_categories() ?
      Thanks !

      #19843
      Olly
      Admin & Mod

        the args list doesn’t really do much there. its the following filter that does the sorting

        
        add_filter('terms_clauses', array($this,'wppizza_term_filter'), '', 1);
        
        #19852
        cubic
        Participant

          I found another way to display only the top level menu by using the shortcode [wppizza type = “navigation”].
          There may be simple, but it works!

          
          function my_nav(){
          $terms = get_terms(array(
          'taxonomy' => 'wppizza_menu',
          //'parent' => 0,
          ) );  
          foreach ( $terms as $pterm ) {
          if($pterm->parent != 0){
          $exclude[]=$pterm->term_id;
          }
          }
          $exclu=implode(",",$exclude);
          echo do_shortcode( '[wppizza type="navigation" exclude="'.$exclu.'"]' );
          }
          
        Viewing 3 posts - 1 through 3 (of 3 total)
        • The topic ‘Get Categories and orderby’ is closed to new replies.