mysql query on wp_user and user_meta problem

In usermeta table WordPress stores many serialized data. So direct meta_value would not work I think. So try the below query- SELECT a.id, a.user_email, a.user_registered, a.user_login, b1.meta_value AS first_name, b2.meta_value AS last_name, b3.meta_value AS qualified, b4.meta_value AS referrer, b5.meta_value AS view_type, b6.meta_value AS ref_by, b7.meta_value AS wp_optimizemember_custom_fields FROM wp_users AS a INNER JOIN wp_usermeta AS … Read more

$wpdb->get_var not returning count

In your code it is actually counting the query you have inserted in $testargs. In your case you entered one. So it is giving you back one. If you need to get the count on WordPress users table then write the query like below- global $wpdb; $total_query = “SELECT COUNT(*) FROM {$wpdb->users} AS total_count”; $total … Read more

Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?

Using WordPress’s wp_postmeta will help you a lot, instead of creating a new table. Functions like get_post_meta(), update_post_meta(), add_post_meta() etc, are readily available for use. All you need is to create a meta_key (which in this case will be wp_likes) and the meta_value (number of likes will be stored), which can be easily retrieved using … Read more

Plugin MySQL SELECT custom data and filter on user meta

Without a proper SQL query in the question is not possible to write a proper query in the response, but following your pseudo-code approach: SELECT custom-data FROM custom-table LEFT JOIN wp_users ON custom_data.user_id = wp_users.ID LEFT JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id WHERE some-condition AND wp_usermeta.meta_key = ‘flag’ AND wp_usermeta.meta_value=”flagvalue” So basically, you need to … Read more

mysql_escape_string PROBLEM

All the mysql_ functions were deprecated in PHP 4.3 and the only currently supported version of PHP where it’s still available is 5.6. These functions have been completely removed in PHP 7. Switch to using mysqli_ or PDO functions instead.