doupishan3309 2012-05-12 12:32
浏览 34


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.

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



  • ¥50 STM32L431RCT6 定时器2中断发起ADC 采样问题
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker