dppb79372 2016-04-14 06:22
浏览 69
已采纳

WordPress - 删除导航菜单项时,链接的页面也在删除

I am trying to develop a custom plugin through which I have to add and delete new items to my nav menu.

And I have saved the term_object_id from wp_term_relationships of each menu tem.

When trying to remove an item from menu it also deleting the linked page , I am trying to delete the menu item using the following function,

function removeMenuEntry($menu_id,$menuterm){    
     $itemData =  array(
        'menu-item-object-id'   => $menuterm,
        'menu-item-status'      => 'draft'
     );
     wp_update_nav_menu_item($menu_id, $menuterm, $itemData) ;  
}

I also tried with the follwing method, but same result,

function removeMenuItem($term_menu){
    global $wpdb;
    $sql = " DELETE FROM wp_term_relationships WHERE object_id = '$term_menu' ; ";
    $wpdb->query($sql);
    $sql = " 
    DELETE FROM wp_posts
    WHERE ID=(
    SELECT post_id from wp_postmeta
    WHERE meta_key='_menu_item_object_id'
    AND meta_value='$term_menu'
    ) AND post_type='nav_menu_item' ; ";
    $wpdb->query($sql);
    $sql = " SELECT post_id from wp_postmeta
             WHERE meta_key='_menu_item_object_id'
             AND meta_value='$term_menu' ";
    $result_state = $wpdb->get_results($sql,ARRAY_A);
    $sql = "DELETE from wp_postmeta
            WHERE post_id=".$result_state[0]['post_id']." ";
    $wpdb->query($sql);
}
  • 写回答

1条回答 默认 最新

  • dongwei9771 2016-05-03 05:20
    关注

    This code is working for me. Please check your entire code whether there is another code or function like ,

    wp_delete_post( );
    

    added for deleting the post.

    Or try to run the query from your query browser.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教