Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert query in wordpress database

I have a email subscription to my site and I want to insert to my Wordpress database so I can export the email listing. I already created table wp_email_subscription with 4 fields ID, name, email and date created. what will be the query for this? is there any wordpress database script to use?

like image 438
Alyssa Reyes Avatar asked Feb 23 '14 06:02

Alyssa Reyes


People also ask

How do I run a query in a WordPress database?

Below is an example of querying the database for posts within a category using WP_Query class. $query = new WP_Query( 'cat=12' ); The result will contain all posts within that category which can then be displayed using a template. Developers can also query WordPress database directly by calling in the $wpdb class.

How do I interact with WordPress database?

WordPress provides a set of functions to interact with databases using the $wpdb object. Since it's a global object you can call this function anywhere using global declaration. global $wpdb; You can see a full explanation of wpdb on the WordPress codex site.


1 Answers

$wpdb->query("INSERT INTO wp_email_subscription (name, email, date) VALUES ('$name', '$email', '$date')"  );

This is if you want to insert values to your table. You do not have to use $wpdb->email_subscription for the prefix as it's the table you created yourself, otherwise, if you were inserting values to default WordPress tables you would prefer doing $wpdb->users etc.

like image 132
wingskush Avatar answered Nov 02 '22 20:11

wingskush