Tag Info

Hot answers tagged

5

This answer is the way I would take to solve the issue if I had to face it, it means is not the answer but one of the possibilities. All the operations I will suggest should be run on a development/local server on a backup of database and not on production nor on original database. If you have 26,000 posts but post id like 4,863,166,253 there are zillions ...


5

There is no build in function to achieve what you want, at least not for complicated meta queries like this. If you need to use build in functions for this, the best will be to make use of WP_Query. To make the query faster and to skip the unwanted returned array of WP_Post properties, and because you are only interested in post count, you can use the ...


4

This doesn't have anything to do with WordPress or your user's passwords. What it means is that your MySQL server is still using the old-password-hash mechanism, which was changed in MySQL 4.1. The PHP mysqli client is newer and doesn't support the old password mechanism. Since this causes an error, WordPress falls back to the old mysql client, which does ...


4

This is what I've found. I'm using a filter to filter the ORDER BY on the SQL query generated by WP_Query. The filter is this posts_orderby. And with it, you can write a custom ORDER BY for the query. I'm gonna show you an example. add_filter('posts_orderby', 'posts_orderby'); function posts_orderby($orderby_for_query) { $orderby_for_query = ...


3

This is all depends on what queries do you run on a page, are you using simple or complicated queries etc. There are really no set minimum or maximum amount of queries to a page. You will need to look in context of your site specifically and weigh the amount of queries to what is actually happening on your page. Wordpress can be quite harsh on resources ...


3

The insert method of $wpdb already scapes the data taking care of SQL injection. What you should worry about is about data sanitization and validation. For exmpla: Sanitization What type of data do you accept in $votes? A integer value? If so, be sure $votes contains a integer value. You cuold do it, for exmaple, using intval function from PHP. This is ...


3

I had the exact same issue. The problem is not one that can be fixed without modifying some code that you probably shouldn't (or perhaps writing a filter or a 'drop-in'). The issue is the CAST directive in the SQL statement. It CASTS the entire table before it does anything, with the amount of records you have, its going to take a while. Capture the query, ...


2

Queries ofcourse. It's faster... But in this case just please delete you wp site and start with something faster... here is my superfast framework for you... <?php /*Your bunny wrote */ I did tests, 0.0000001 runtime vs WP usually 0.7-2.8 Sarcasm off P/S/ This question have no sence since using direct queries and output of the variables isn't use ...


2

wpdb::insert already protects against SQL injection, it's a wrapper for wpdb::prepare For insert(), you can pass a third "formats" argument for extra sanitization: $wpdb->insert( 'votes', array( 'votes' => $votes, 'competition' => $competition, 'uid' => $uid ), array( '%s', // $votes will ...


2

No! WordPress will not protect against SQL injection in this case. You need to do so yourself, using $wpdb->esc_like and $wpdb->prepare: if ( isset( $_GET['q'] ) ) { // WordPress forces magic quotes (god knows why), unslash it $value = wp_unslash( ( string ) $_GET['q'] ); // Escape like wildcards so that MySQL interprets them as ...


2

You should be fine deleting empty custom fields. The main reason is, that get_post_meta( $id, 'metakey', true ) returns an empty string if the field is not set, so it is the same as having an empty record set. get_post_meta( $id, 'metakey', false ), returns an empty array if no value is set, so you should be fine too. The only problem you could face is ...


2

You have the following methods of the $wpdb object: $wpdb->flush() that contains a call to mysqli_free_result() or mysql_free_result() if not supported. $wpdb->check_connection() that contains a call to mysqli_ping() or mysql_ping() if not supported. You can of course use all your PHP functions in WordPress. Here's an example based on the \wpdb ...


2

Okay, this always seems to happen to me. I spend ages looking for an answer and finally decide to give up and post here and then one more search finds enough to solve it. Anyway, this is what worked for me: update wp_posts set post_content = replace(post_content, '[/tab] [tab title="1024x576"] <table class="screenshot-table">', '[tabby title="1024 ...


2

Check all credentials in wp-config.php. And don't forget about table prefix.


2

Please use $wpdb to interact with the Database. global $wpdb; $wpdb->update( // Table name $wpdb->posts, // New values array( 'post_type' => 'product', ), // SQL "WHERE" clause base / affected rows array( 'post_type' => 'post', ), // Data Type (available: %s string, %d integer, %f float) '%s', // SQL "WHERE" ...


2

wpdb doesn't include such kind of API, mostly since it descended from ezSQL which didn't either (as far as I remember). While there are some helpers for insert/update stuff, most of query abstraction happens in WP_Query since that's where bulk of complicated querying is typically going on.


2

If I'm not missing something, the below should work for you. It is pretty much straight from the Codex: WP_Query - Custom Field Parameters. Do it like this: $args = array( 'post_type' => 'post', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'color', 'value' => 'red', ...


2

If you did want to lock things down.... a normal wordpress site will usually only require the database user to have SELECT, INSERT, UPDATE and DELETE. If you want to use the automatic update feature it will also require CREATE and ALTER. Some plugins may require other permissions but most won't.


2

First off, you should not be handing an untrusted input (in this case, $_GET['id'] to your database. Always SQL-escape the query and validate/sanitize the data. (In the code snippet below, it's SQL-escaped using $wpdb->prepare() for escaping and int typecasting to sanitize to integer value). Secondly, the $wpdb object provides more than just the query() ...


2

In typical use cases the performance cost of booting WordPress core for page load is significantly higher than querying for data. In other words it doesn't quite matter, because it won't be a bottleneck. You have to estimate: How close your data is to native WordPress concepts How much work (if any) it would be required to put it in such representation ...


2

Try to replace: AND meta_value LIKE %s with AND meta_value LIKE '%%%s%%' so your SQL will become: AND meta_value LIKE '%The%' instead of: AND meta_value LIKE 'The'


2

You can just call get_user_meta without specifying a key, and it will return all MetaValues for the user. $userdata = get_user_meta( $userID ); You may have to do a mapping for displaytitles of the Metavalue, as they are returned in an array, where the keys are the databasevalues of your metakeys. For example, you may get ...


2

This will create a new admin user called username with password: password in a database called DATABASE Try this: First create a row in wp_users. Replace DATABASE with your database name, username with your choosen username, password with your password of choice. INSERT INTO `DATABASE`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, ...


1

Bulk of WP's native data structures aren't meant for direct MySQL access. They are typically accessed via PHP APIs which take care of MySQL generation/execution and many more things, such as allowing to filter data, caching it for performance, and so on. Your issue here is that from MySQL point of view meta values aren't related to each other, but only to ...


1

This constant is actually never defined in core code at all. You can define it yourself in wp-config.php configuration if you need to, but core doesn't need it defined for normal operation. It only exists for re–configuring into running untypical setup.


1

insert is not a static method. So you can't call it like this: wpdb::insert(/*...*/). You'll need to do something like: global $wpdb; $wpdb->insert(/*...*/); Or create your own instance: $db = new wpdb('dbuser', 'dbpassword', 'dbname', 'dbhost'); // change these! $db->insert(/*...*/);


1

You can use Wp function for this. wp_delete_user(); this function work with user id. you can get all subscribers user id with this way: get_users() getting your filtered users. $get_subscribers = get_users('role=subscriber'); foreach($get_subscribers as $user){ wp_delete_user($user->ID); }


1

As @Charleston Software Associates mentioned, the DESCRIBE query should not be executed if the table doesn't exist. The best solution, as he pointed out, is to prevent the error from occurring in the first place. To do so, patch wp-admin/includes/upgrade.php as follows: Change the following line from dbDelta(): $tablefields = ...


1

Generally, WordPress has functions to handle what you want, it is much preferable to use them. For example, because it isn't a complete list, some of those are: wp_delete_user() wp_create_user() wp_insert_user() wp_update_user() The class behind (most of) it is: WP_User If you really need to know the SQL that is used, I would suggest you read the ...


1

You're including the table prefix, but $wpdb takes care of that. Change: $query = $wpdb->prepare( "SELECT * FROM $wpdb->wp_terms INNER JOIN $wpdb->wp_term_taxonomy ON ($wpdb->wp_terms.term_id = $wpdb->wp_term_taxonomy.term_id) WHERE $wpdb->wp_terms.name LIKE %s AND $wpdb->wp_terms.count > 0", $wpdb->esc_like($keyword) . '%'); ...



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