Guest User

Untitled

a guest
Jan 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. $menu_object = wp_get_nav_menu_object('My Menu');
  2.  
  3. $postlist = get_posts('orderby=date&sort_order=DESC');
  4. $posts = array();
  5. foreach ( $postlist as $post ) {
  6. $posts[] += $post->ID;
  7. }
  8.  
  9.  
  10. $menuitems = wp_get_nav_menu_items( $menu_object->term_id, array( 'order'=>'ASC','orderby' => 'menu_order',
  11. 'post_status' => 'publish', 'output' => 'OBJECT', 'output_key' => 'ARRAY_A'));
  12.  
  13.  
  14. $title = array();
  15. $item_id = array();
  16. $parent_id = array();
  17. $index = 0;
  18.  
  19. foreach($menuitems as $item){
  20.  
  21. $title[] += $item->title;
  22. $item_id[] += $item->ID;
  23.  
  24.  
  25. if($index === 2){
  26. if($item->title !== get_the_title($posts[0])){
  27.  
  28. wp_update_nav_menu_item($menu_object->term_id,0, array(
  29. 'menu-item-title' => __(get_the_title($posts[0])),
  30. 'menu-item-classes' => 'home',
  31. 'menu-item-url' => get_permalink($posts[0]),
  32. 'menu-item-status' => 'publish',
  33. 'menu-item-parent-id' => $item_id[$index-1],
  34. 'menu-item-position' => -1));
  35.  
  36. }
  37. }
  38. ++$index;
  39.  
  40.  
  41. }
Add Comment
Please, Sign In to add comment