Block search SQL from happening

It’s possible to avoid SQL execution in WP_Query with the posts_pre_query filter. It’s e.g. used by plugins to outsource the default search to 3rd party search engines. Here’s an example how we can override the main search query on the front-end, with an empty posts array and avoid running the SQL search query: add_filter( ‘posts_pre_query’, … Read more

Differences between add_post_meta and update_post_meta

This: update_post_meta(42, ‘my_meta_key’, [ ‘my_meta_value_1’, ‘my_meta_value_2’, ‘my_meta_value_3′, ]); Changes a single post meta, but the value is an array, and you can’t put a array in the database, it wants a string for that column. So WordPress serializes it into a string and saves the result. So I have a question, are either of these … Read more

Relationship between performance and database size

A bigger database isn’t per definition slower, and a smaller database isn’t per definition faster. When a table contains a large amount of information, it could take longer for queries to get their results, depending on the type of query, the amount of data you want to return, the table structure attributes, types and indexes. … Read more

Large database causes slow load

DISCLAIMER : Not a WordPress Developer, Just a MySQL DBA There is a special table structure in Oracle called a Materialized View. Basically, it is built by performing a JOIN query (using no WHERE clause) and storing the result set. Then, simply SELECT from that static result set rather than rebuilding each JOIN result. First, … Read more

PHP variable in WordPress database query

The WPDB prepare method is what you’re after, as this will prep your data for passing to a query and also ensure data matches the type its intended to be whilst also handling quoting where necessary at the same time. Fixing your code could be a matter of.. $voucher=”MK0186″; $is_in_database = $wpdb->get_results( “SELECT * FROM … Read more

Cannot unserialize WordPress serialized values in `wp_options` table?

Your problem is that serialized strings contains escape slashes that are not evaluated as such, because the wrapping quote is a single quote. You are using: $v = ‘a:2:{i:0;b:0;s:8:\”auto_add\”;a:0:{}}’; // wrong You have to use either $v = “a:2:{i:0;b:0;s:8:\”auto_add\”;a:0:{}}”; // ok or $v = ‘a:2:{i:0;b:0;s:8:”auto_add”;a:0:{}}’; // ok By the way, you should never manually unserialize … Read more

Universal problem: first request after ~25 second inactivity always slower (~1 second) than subsequent requests (~1/10sec)

Without looking at your box to see exactly what’s going on, here are some potential avenues of slowness: Potential Causes Apache Apache is usually configured in such a way that a single httpd process is always running in the background. When a request comes in over the wire, it spins up a new httpd process … Read more

WooCommerce – Query for ordered products

Fixed query select p.ID as order_id, p.post_date, i.order_item_name, max( CASE WHEN im.meta_key = ‘_product_id’ and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID from wp_posts as p, wp_postmeta as pm, wp_woocommerce_order_items as i, wp_woocommerce_order_itemmeta as im where p.post_type=”shop_order” and p.ID = pm.post_id and p.ID = i.order_id and p.post_date BETWEEN ‘2016-01-14 00:00:00’ AND ‘2016-01-14 23:59:59’ … Read more