Hot answers tagged

2

You should use $wpdb->prepare for queries, as it does all the sanitizing and escaping for you. Also, key is reserved as a field name in MySQL: function ch_details_from_id($id) { global $wpdb; // or try using " . $wpdb->prefix . "ch_guests $query = "SELECT * FROM $wpdb->ch_guests WHERE guest = %d"; $details = $wpdb->get_results( ...


2

The direct answer to the question "Is there a way to get 3+ dimensional array from a single MySql command" would be yes, sort of - WordPress routinely stores and retrieves multidimensional data from MySQL rows by serialize()ing and unserialize()ing structured data to/from a string format, so it's certainly possible using WordPress's database interaction ...


2

No, wpdb::delete does not handle anything other than WHERE field = X. You can just use the query method instead: $ids = implode( ',', array_map( 'absint', $ids ) ); $wpdb->query( "DELETE FROM table_name WHERE ID IN($ids)" );


1

Caching can be anywhere, starting with request caching on mysql components side (unlikely to impact in this case), and object caching on wordpress side. You are probably doing something wrong in your code, but it is always better to use the API (or wordpress admin as a front end to it) to delete things then to try to delete them by directly accessing the ...


1

Here issue with the column name. You are using column key in the query which is the default keyword/index in mysql. For resolving this kind of issue just use the "Grave accent(`)' symbol in the query for the column name, No need to change the column name. So in your case the right query is $details = $wpdb->get_results("SELECT * FROM " . ...


1

Because $pageposts is an array of post IDs, but you need to pass a post object to setup_postdata - pull the objects instead: SELECT $wpdb->posts.* [rest of query] Note that, since you're not paginating, you don't need SQL_CALC_FOUND_ROWS



Only top voted, non community-wiki answers of a minimum length are eligible