Get All Results From Other Users That Share The Same Custom User Meta As Current User

You can use get_current_user_id to get the id of the user currently viewing the page, and get_user_meta to get the site_id associated with that user. For example: <?php $user_id = get_current_user_id(); $site_id = get_user_meta($user_id, ‘site_id’, true); Note: This does assume there is a user logged in, you might get unexpected results if there isn’t. So … Read more

get posts whether meta_key exists or not

Thanks to @Hobo’s answer which gave me the clue for moving pm2 condition to the join statement SELECT p.ID, p.post_content, p.post_title, p.post_excerpt, pm1.meta_value as meal_date, pm2.meta_value as meal_plan, t.name as meal_type FROM wp_posts AS p LEFT JOIN wp_term_relationships AS r ON (p.ID = r.object_id) INNER JOIN wp_term_taxonomy AS x ON (r.term_taxonomy_id = x.term_taxonomy_id) INNER JOIN … Read more

AWS Lightsail WordPress – connect to database on instance using mysqli

//Params to connect to a database $dbHost = “*static ip of wordpress site*”; This should be $dbHost = “localhost”; instead, or “127.0.0.1” (or even “::1”). localhost uses a separate virtual network interface that makes sure traffic between services on your Linux VM doesn’t leave the VM In general it’s safer to use localhost rather than … Read more

Wpdb query with dynamic table name

I will start with the question. From the sql error output we see this SELECT * FROM WHERE dbID = 719 This tells us that $sanitized_search_language has no value, so check it first. Now for the BIG problem with this query! You used get_results with a sql query that has variables as is, get_results doesn’t … Read more