Advertisement
campusboy

Untitled

Jun 15th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2. add_filter( 'wp_get_nav_menu_items', function ( $items, $menu, $args ) {
  3.  
  4.     $cats      = get_categories();
  5.     $items_new = [];
  6.  
  7.     /**
  8.      * @var WP_Term $cat
  9.      */
  10.     foreach ( $cats as $key => $cat ) {
  11.         $post = new WP_Post( new stdClass() );
  12.  
  13.         $post->ID          = $key;
  14.         $post->post_author = 1;
  15.         $post->post_title  = $cat->name;
  16.         $post->post_type   = 'nav_menu_item';
  17.  
  18.         $post->object_id = (string) $cat->term_id;
  19.         $post->object    = $cat->taxonomy;
  20.         $post->type      = 'taxonomy';
  21.         $post->title     = $cat->name;
  22.         $post->url       = get_category_link( $cat );
  23.  
  24.         $post->target      = '';
  25.         $post->attr_title  = '';
  26.         $post->description = '';
  27.         $post->classes     = [ '' ];
  28.         $post->xfn         = '';
  29.  
  30.         $items_new[] = $post;
  31.     }
  32.    
  33.     return $items_new;
  34. }, 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement