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?
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.
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.
$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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With