How to check if a value exists in one of two database tables

You had not very good architecture for your application. Best way is in save user information in one table and use separated fields or linked table for save extra information. In your case you case use UNION and check tables in one query. And correct way is use SELECT COUNT(*) and check result instead SELECT … Read more

How do you build a database-centric site in WP?

It’s not complicated to connect to custom tables in WP context and query them, using native wpdb class. However “not complicated” is about all there it. WP API functions are primarily aimed at querying its own data structures. While wpdb does have some helpers, they are simplistic and not meant for more elaborate custom queries. … Read more

ERROR: “Table Prefix” must not be empty

You need to have the table prefix set in the wp-config.php file. It must be matching the same value in tables of your database, the default value is “wp_” but if you used a customized value for your tables to enhance security which is a good practice, you need to update your $table_prefix = ‘wp_’; … Read more

$wpdb->prepare returns empty array

Try with: function getComponents($page_id, $currentLanguage) { global $wpdb; $result = $wpdb->get_results($wpdb->prepare( ” SELECT id, post_content, post_title, post_excerpt, post_name, m1.meta_value AS ‘template’, m2.meta_value AS ‘home_description’ FROM {$wpdb->posts} p JOIN wp_term_relationships r ON p.ID = r.object_id JOIN wp_terms t ON r.term_taxonomy_id = t.term_id WHERE t.slug=%s AND post_parent = %d AND post_type=”page” AND post_status=”publish” ORDER BY menu_order ASC … Read more