Articles of wpdb

$wpdb->insert – inserting multiple rows

How do I use $wpdb->insert to insert multiple rows. Here is my code. for($i=0; $i<=$urlCount; $i++) { $stat = $wpdb->insert( ‘WP_URLS’, array( ‘POSTID’ => $post->ID, ‘URL’ => $_POST[‘url’.$i] ) ); } This code works only for the first insert (ie, when $i = 0 , when value is url_0 ). Sometimes the URL count will […]

Doing a loop with multiple DBs simultaneoulsy

I have a website setup made up of with more than 3-4 WordPress setups as subdirectories of main. For example: Site | ———- Site/Site1 | ———- Site/Site2 | ———- Site/Site3 Each have separate codebase, separate DB for itself. The Database server is one and the host directory is also one. Basically we can say these […]

Using WPDB class

I want to use the wpdb class on my external page not associated with wordpress. I tried to include the following on the php file: // include wordpress functions include( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-load.php’); require_wp_db(); global $wpdb; Now I made a query using $wpdb->query $product_info_query = $wpdb->query(“select p.products_id, p.products_type, p.img_display, p.products_sku, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, […]

ob_end_flush error when using wpdb in plugin

I created a small plugin to test database interactions in wordpress. I have a small function that inputs the arguments to the table. If i call my function in a themefile it inputs my test values to my table, but if i call it from another plugin i get this error: Notice: ob_end_flush(): failed to […]

Inserting large amounts of data into a custom table during plugin install

I am working on a WordPress plugin that creates several new tables into the database. It also loads some default data into the tables from CSV files. Most of these are small and loading the data works fine. One, however, is a zip code database meant to be loaded with just over 43,000 rows of […]

How Can I Use $wpdb in PayPal IPN file?

I’m currently writing a plugin that requires the PayPal IPN, since the IPN is not inside the main plugin file, I have no way to use $wpdb. If you know a way to do this that will work with all WordPress installations it would really help me! Thanks in advance!

How to prevent $wpdb->prepare stripping a leading zero in variable value?

I have a simple database_read function and per accident I noticed order_id’s starting with a leading zero would not give me the expected results. It turns out using $wpdb->prepare strips out leading zero’s. How can i prevent this and still use the prepare method? Here’s the function: function database_read($order_id) { // $order_id = intval($order_id);//this will […]

Need help writing a $wpdb query

I am trying to search through post meta for keyword matches but I’m new to MySQL and I don’t know how to write my query. I can write a basic query for post_title matches but I don’t know how to properly jump across tables. In pseudo code, my query would be “SELECT post_id FROM $wpdb->postmeta […]

Cannot update custom database table row

I am trying to update a row in a custom database table by $wpdb->update();. In my opinion my code is right but for some reason my database row doesn’t update. Can anyone help me with this? I want to update a the status of a transaction in the table wp_mollie_transactions where the transaction_id is equal […]

MySQL LIKE not working

It seems MySQL’s LIKE operator behaves like a = operator. The following MySQL query returns the expected result (1 entry): $meta_key = ‘_locality’; $meta_value = ‘The Hague’; $post_ids = $wpdb->get_col( $wpdb->prepare( ” SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value LIKE %s “, $meta_key, $meta_value ) ); But the following returns an empty […]