wp_delete_auto_drafts() deletes links in menus

This is what normal query run by wp_get_associated_nav_menu_items() looks like: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.id = wp_postmeta.post_id ) WHERE 1 = 1 AND wp_posts.post_type=”nav_menu_item” AND (( wp_posts.post_status <> ‘trash’ AND wp_posts.post_status <> ‘auto-draft’ )) AND (( wp_postmeta.meta_key = ‘_menu_item_object_id’ AND Cast(wp_postmeta.meta_value AS CHAR) = ‘3111’ )) GROUP BY wp_posts.id ORDER … Read more

Adding first and last class to Menu on top level only

I would lean very much towards a custom walker for this but I think I’ve managed to make it work using part of that code and some of my own. function add_position_classes_wpse_100781($classes, $item, $args) { static $fl; if (0 == $item->menu_item_parent) { $fl = (empty($fl)) ? ‘first’ : ‘middle’; $classes[] = $fl.’-menu-item’; } return $classes; … Read more

How to make a plugin auto-add item to nav menu

this is the general gist of what you need to do, you’ll want to add some checks in here, make sure you get a valid menu returned, etc.. $locations = get_theme_mod( ‘nav_menu_locations’ ); $menu = wp_get_nav_menu_object( reset( $locations ) ); // get first item in menu locations array $menu_item_data = array( ‘menu-item-object-id’ => $your_page->ID, // … Read more

Check if wp_nav_menu items have submenus

If I understand correctly, you want links with submenus to have an attribute of aria-haspopup. If this is correct, you should be able to do so using the nav_menu_link_attributes filter (WP 3.6 and above). You can also get around the necessity of having to write a custom Walker to check if an item has children … Read more

Custom Nav Walker sub-menu HTML construct

Solution: Copy paste the below code into your function. and then in template use my_nav_menu($menu_location); //put this in your functions class MY_Menu_Walker_Ext extends Walker { var $tree_type = array(‘post_type’, ‘taxonomy’, ‘custom’); var $db_fields = array(‘parent’ => ‘menu_item_parent’, ‘id’ => ‘db_id’); function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) { $output .=”<li><h2 … Read more

Auto add pages to category menu

Yes, it’s possible. Depending on the way you build your menu, you’d have to call the posts like this (fill in placeholders): // Call/Query the posts related to the category: $your_cat_related_cpts = get_posts( array( ‘post_type’ => ‘YOUR_CUSTOM_POST_TYPE’ ,’category’ => ‘YOUR_CATEGORY’ ) ); // Append them to your menu: foreach ( $your_cat_related_cpts as $content ) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)