Tag Info

New answers tagged

1

Why not use get_comments(), instead of trying to roll your own with $wpdb? function display_sitewide_comments() { $sites = wp_get_sites(); $network_comments = array(); $max = 20; foreach( $sites as $site ) { switch_to_blog( $site->blog_id ); $args = array( 'number' => $max, 'status' => ...


1

First, you're using prepare() wrong. Should be this: $wpdb->prepare("SELECT Active FROM testers WHERE user_id = %s", $user_id) If you have any debugging enabled, it will throw an error from your code. Which may make your location header not work properly. Second, the get_var() function indeed returns null when there are no results. Third, setting a ...


2

You want the query to look like this: SELECT email FROM wp_my_users WHERE email = 'mail@example.com' instead of this: SELECT email FROM 'wp_my_users' WHERE email = 'mail@example.com' So try to construct your query with: $sql = "SELECT email FROM {$my_table_name} WHERE email = %s"; $result = $wpdb->get_var( $wpdb->prepare( $sql, $email_address ...


0

You have a structural problem with your data. Serialized data in the database is terrible if you need to search over pieces of that serialized data. There is no reliable, efficient, and certainly no easy, SQL query to search over serialized data. "serialization" is a PHP mechanism. It isn't SQL. To the database that is just a string. Your only SQL choice ...


0

You can make your script a part of your WordPress post, just use the $wpdb object provided by the WordPress itself. The $wpdb object already has the database connection established and you can use it to perform any database operation: insert, update, query etc... Thisi s preferrable method for doing you DB stuff inside WordPress as you do not have to open ...


1

Read the wpdb docs and don't forget to protect your query: global $wpdb; $table_name = $wpdb->prefix . "item"; $login_name = sanitize_user( $_POST['login_name'] ); //assuming you're dealing with username $prepare = $wpdb->prepare( "SELECT * FROM $table_name WHERE uname = %s", $login_name ); $myrows = $wpdb->get_results( $prepare ); //output ...


1

the _edit_lock is generated each time you edit a post or page. it consist the timecode and the user. so WordPress is knowing who is currently editing it. meta_id post_id meta_key meta_value 9 5 _edit_lock 1388386997:1 if you manipulate it WordPress reacts somehow sensitive ...I tried to fetch how many seconds somebody ...


2

A key must be defined for a table by using a single column, or multiple. So on your code, you need to a line to the sql KEY id (id) - $sql = "CREATE TABLE $table_name ( id int NOT NULL AUTO_INCREMENT, feedurl text NOT NULL, category text NOT NULL, KEY id (id) );";


1

Yes 90-100ms round trip + time to prepare SQL statement + time to execute statement + time to send results back multiplied by the number of times you need to query the database. Sure the connection may stay open but it's an inherently expensive thing to do. Considering that some setups can respond in full in less than 100ms never mind the database ...


0

First of all why you would need custom query for this basic functionality to get users, when WordPress has inbuilt function get_users(). Anyway for custom query, table name is defined as function custom_func(){ global $wpdb; $getTest = "SELECT * FROM $wpdb->users LIMIT 1"; $arrayReturned = $wpdb->get_results($wpdb->prepare($getTest)); } It's ...


2

Since version 3.9 (that will be released soon, actually in beta 2) WordPress will use mysqli to connect to database (3.9- versions use mysql) so you can actually use new wpdb instances and helper function to connect externa values from WordPress. What I suggest is to configure external database using constants in wp-config.php in this way you are sure that ...


0

Did you read this: https://codex.wordpress.org/Custom_Queries I think it will help you understand the basics, then you can take it from there.



Top 50 recent answers are included