Custom Menu Meta field is not giving me url
-
function custom_add_menu_meta_box( $object ) { add_meta_box( 'custom-menu-metabox', __( 'Default Menus' ), 'custom_menu_meta_box', 'nav-menus', 'side', 'default' ); return $object; } add_filter( 'nav_menu_meta_box_object', 'custom_add_menu_meta_box', 10, 1);
I have created a menu meta box named Default Menus.
Here is the function implementation.
function custom_menu_meta_box(){ global $nav_menu_selected_id; $custom_nav_menu_options = json_decode(get_option('ds_custom_nav_menu')); $generatedMenu = []; for($i = 0; $i < count($custom_nav_menu_options); $i++) { $singleMenu = $custom_nav_menu_options[$i]; array_push($generatedMenu, (object) [ 'ID' => 1, 'object_id' => 1, 'type_label' => 'default', 'title' => $singleMenu->pageTitle, 'url' => $singleMenu->link, 'type' => 'default', 'object' => 'default', 'db_id' => 0, 'menu_item_parent' => 0, 'post_parent' => 0, 'target' => '', 'attr_title' => '', 'description' => '', 'classes' => array(), 'xfn' => '']); } $db_fields = false; // If your links will be hierarchical, adjust the $db_fields array below if ( false ) { $db_fields = array( 'parent' => 'parent', 'id' => 'post_parent' ); } $walker = new Walker_Nav_Menu_Checklist( $db_fields ); $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce', ); ?> <div id="plugin-slug-div"> <div id="tabs-panel-plugin-slug-all" class="tabs-panel tabs-panel-active"> <ul id="plugin-slug-checklist-pop" class="categorychecklist form-no-clear" > <?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $generatedMenu ), 0, (object) array( 'walker' => $walker ) ); ?> </ul> <p class="button-controls"> <span class="add-to-menu"> <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-plugin-slug-menu-item" id="submit-plugin-slug-div" /> <span class="spinner"></span> </span> </p> </div> <?php }
I have given type ‘type’ => ‘default’
But how can I get url of this menu while I am going to show it’s not giving me url. But If I use custom, then it is giving me url with this code below:$menu_item->url = ! isset( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url;
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom Menu Meta field is not giving me url’ is closed to new replies.