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

An update for Wordpress 3.9+ - with PHP 5.5 deprecating the mysql_* functions Wordpress has begun using the mysqli if it is available on the server. Your future plugins and code should take this into consideration and stop using mysql_*. Right now, in 3.9, wordpress checks for the availability of mysqli and uses it if available. If not it uses mysql_* but ...


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

I know it might be abit late for answer but I came across similar issue while making my test project. Here's how I solved it. /* apply this filter only on relevant to you pages */ function mb_bail_main_wp_query( $sql, WP_Query &$wpQuery ) { if ( $wpQuery->is_main_query() ) { /* prevent SELECT FOUND_ROWS() query*/ ...


3

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 ...


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`, ...


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

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 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

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

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' => ...


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 ...


2

I am going to guess that you have your code in the theme, probably functions.php. That code will only load when the theme is active, and after_switch_theme only runs after the theme change. There is no before_switch_theme that I am aware of. You will need to have this code in a plugin or a mu-plugin file in order to have it work for all themes. But ...


2

Here, you can get adjacent post for specific post type with custom sql query & with filter get_{$adjacent}_post_where where default adjacent is previous. Also result depends on $current_post_date & comparison operator $op. function bm_get_adjacent_post( $post_id, $author_id, $previous = 1 ) { global $wpdb; if ( ( ! $post = get_post( $post_id ) ) ...


2

MySql DELETE syntax is not very different fiom SELECT, so you can delete from multiple tables using a single query. Taxonomies informations in WordPress are in 3 tables: wp_terms wp_term_taxonomy wp_term_relationships the first 2 contain term / taxonomy informations, the 3rd contains association between terms and posts. The query to delete all tags ...


2

First of all your query is wrong. The right query is $mypost = $wpdb->query($wpdb->prepare("SELECT post_content FROM $wpdb->posts WHERE ID = %d", 2)); Second the $wpdb->query will returns an integer value indicating the number of rows affected/selected. You can check here http://codex.wordpress.org/Class_Reference/wpdb#General_Syntax If you ...


1

From what I can see, you are inserting data in table wp_commentmeta. However the column meta_id has a Primary Key restriction. You can see the table definition at http://codex.wordpress.org/Database_Description#Table:_wp_commentmeta As meta_id has a Primary Key restriction, this column may only hold unique values. The insert statements you have posted show ...


1

When working with database in WordPress you should never use the low lever mysql_* or mysqli_* functions. Always use $wpdb methods, in your case you should use prepare(): $query = $wpdb->prepare( "SELECT post_title from $wpdb->posts WHERE post_title LIKE %s", "%" . $myTitle . "%" ); Moreover, once you are getting a single column, you have ...


1

Ok, you can do this using direct queries with $wpdb or just with WordPress. Generally speaking, if using WordPress, do it the WordPress way. I'm assuming that all the dates are stored using the same format; if they're not, you might need to solve that first. The problem with your code it's that you're using array_unique on an array of objects; if you're ...


1

While the prepare() answer given is correct, if you do need a way to escape a string for an SQL statement manually, use esc_sql().


1

BOOL or BOOLEAN are as far as MYSQL is concerned just replacements/synonyms for TINYINT(1), tiny integer, so using %d for integers is the correct way to do it. Some additional information: Codex: Class Reference - wpdb - Placeholders MySQL: Numeric Type Overview MySQL: Boolean Literals MySQL: Integer Types



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