I have to write many custom queries for my new plugin. I know that I can use wpdb Class.

But it is really complex for me when I have to write long queres with lots of where closes and join queries using wpdb Class.

But I can write those queries very easily in normal way. I can create a new connection and I can write queries and I can run them using mysqli_query function.

Is there any problem if I do it as above mentioned method?

  • Not sure but, If you will use "mysqli_query" function then to make connection you have to specify Database name and that can be problem if you are making a plugin. For e.g. If someone install you plugin then how your plugin will know what is the name of database. In other word you have to find a way to dynamically assign database name and other options also like hostname etc, so it will work for everyone. Since $wpdb directly target wordpress database, so there is no such kind of problem if you use $wpdb. – Rishabh Nov 2 '16 at 4:11
  • Yes, you can use wpdb to write custom queries. you have to call "global $wpdb;" in respective function. For reference you can follow wordpress codex:: codex.wordpress.org/Class_Reference/wpdb – BlueSuiter Nov 2 '16 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.