meta_query for a string inside a meta field containing a comma-separated list

Is there a smart way to meta_query so it matches just “IS, but not “TS-IS”? The WordPress meta query class (WP_Meta_Query), which among others, is used with the posts (WP_Query) and users (WP_User_Query) query classes, supports REGEXP (since WordPress 3.7) as the compare value, so you could use that with a RegEx (regular expresion) pattern … Read more

WordPress missing user roles on local dev machine. Live site works fine

I just exported the live database, replaced all occurences of the live siteurl with the local one, and imported on my dev machine. Finding/replacing with a text editor breaks serialized data; you must change values with MySQL queries in phpmyadmin: UPDATE wp_options SET option_value = replace(option_value, ‘http://www.olddomain.com/’, ‘http://www.newdomain.com/’) WHERE option_name=”home” OR option_name=”siteurl”; UPDATE wp_posts SET … Read more

Show individual author rank from query of cumulative post view count for all authors

First you can replace ‘posts_per_page’ => ‘10000000000’ with ‘posts_per_page’ => -1 to remove the limit. If you want to show the user rank, you can add a $rank counter in the foreach loop: $rank=0; // output the result: user, total postview count, latest post foreach ($output as $user){ $rank++; $profile = get_userdata($user[‘id’]); $query = get_posts( … Read more

Separate table or usermeta

The obvious advantage of user meta is that you can use the WordPress API to record and retrieve these extra columns, without writing extra PHP classes or SQL queries. The wp_usermeta table is pretty well indexed, in fact, it uses one row per field (rather than one column if you use a custom table), and … Read more

Select User by Joining Multiple Meta Value Results

Try this one with additional join on metadata SELECT u.ID, u.display_name FROM wp_users u LEFT JOIN wp_usermeta um1 ON u.ID = um1.user_id LEFT JOIN wp_usermeta um2 ON u.ID = um2.user_id WHERE um1.meta_value=”value1″ AND um1.meta_key = ‘key1’ AND um2.meta_key = ‘keyA’ AND um2.meta_value=”valueA” GROUP BY u.ID Also use group by

How to insert new element to existing array in usermeta?

Let’s analyze your code and what it does. Assuming that the current fruits stored in the database are ‘pineapple’ and ‘orange’, get_user_meta(2, ‘fruits’, false) will return something like this: array( array( ‘pineapple’, ‘orange’ ) ) This is because you passed false as the third argument, $single. The function returns an array if $single is false … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)