Slow Mysql Queries

WP options (which is one of the most basic and used storage APIs) can be stored with or without “autoload” setting. Usually this is reasonable, since many options will be checked on each and every page load, so loading them in bulk during core load is much more efficient than individually. Problems usually start when … Read more

How to get last updated row or ID in wordpress

I had the same problem. There is no equivalent function. $wpdb->insert_id works only after $wpdb->insert Alternative way If it’s an update, you can either get the id with a query based on the data you have got, or most of the time, you should have already got the id before update it. global $wpdb; $data … Read more

How to add and SQL query of posts only published

You should be able to get away with just adding AND $wpdb->posts.post_status=”publish” at the end. $prepare_string = ” SELECT DISTINCT ID FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) LEFT JOIN $wpdb->postmeta AS mt1 ON ( $wpdb->posts.ID = mt1.post_id ) WHERE ( ( $wpdb->postmeta.meta_key = ‘event_date’ AND $wpdb->postmeta.meta_value >= %d ) OR … Read more

How to get the post_id from postmeta

There’s the WordPress meta API for retrieving meta values from the wp_postmeta table, but the API doesn’t provide a function for retrieving the post ID (post_id value), but you can use custom SQL as in your code. However, $wpdb->get_col() returns an array of values (upon success), so that’s why you get the “Array” when you … Read more