doupishan3309 2012-05-12 12:32
浏览 34
已采纳

在Wordpress中创建/更新新帖子后更新/插入自定义表格

Is there any way to update a couple of mySQL tables when I create a new post or edit an existing post.

For example, I have a custom post type called 'television'. I have a custom table called tvoffers which stores offers for a particular television.

So, if I am writing a post on say Sony Bravia 32" LCD, I can also enter information in the TV offers such as :

offer_id   post_id  Offer_name   Offer_code    Offer_link   Price

?

Is this possible to do? Any help will be most appreciated.

  • 写回答

1条回答 默认 最新

  • douqing0713 2012-05-12 12:50
    关注

    You need to use a Wordpress hook. In this case, you should apply an action hook to the save_post action (or any other action hooks that you think would be a better match; lots of them exist):

    add_action( 'save_post', 'update_database_with_info' );
    
    function update_database_with_info( $post_id ) {
        // Now do something with the post
    }
    

    This code should be added to your functions.php file, located in your themes directory.

    Note that an updated page also triggers save_post, so you might want to take this into account in your function.

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

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据