douwen7331 2013-06-20 14:16
浏览 63

Wordpress自定义插件wpdb无法识别

I'm developing my first wordpress plugin where I can list all my employees with some CRUD functionality.

When I click "Add Employee" I get a new window where I can fill in all the fields for an employee and after that I click "Save"

But when I click save I get the following PHP error:

   Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\wp-custom-plugin\wp-content\plugins\werknemers\employee_crud_functions.php on line 15

And when I look at line 15 the code is:

 $wpdb->insert( ... )

and this is my form with the action set to that php page

 <form method="POST" action="<?php bloginfo('url') ?>/wp-content/plugins/werknemers/employee_crud_functions.php">

I assume that the file is not aware of the $wpdb variable. But how can I let that php page know what it is? Or am I using it all wrong?

  • 写回答

3条回答 默认 最新

  • doudun2565 2013-06-20 14:20
    关注

    You are quite possibly missing the global declaration of $wpdb.

    From the wpdb reference.

    WordPress provides a global variable, $wpdb, 
    which is an instantiation of the class already 
    set up to talk to the WordPress database. 
    Always use the global $wpdb variable. 
    (Remember to globalize $wpdb before using it in any custom functions.)
    

    You need to use it like this.

    global $wpdb;
    //do something with it.
    
    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM