Articles of optimization

Function to retrieve IDs of posts, cache results, and improve wp_query

I’m looking to optimize db performance by creating a function that retrieves IDs of posts in a certain category and caches results. So instead of having a query like: SELECT … WHERE 1=1 AND wp_posts.ID NOT IN ( SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy […]

Disable Garbage Collection?

I have a WP site which creates 500’s errors for about 2% of Apache requests (mostly bots and crawlers). I’m not able to stack trace most of those requests with 500’s neither to PHP or MySQL errors as well Apache error logs. Apache access log example for crawlers: – – [06/Oct/2015:11:23:49 -0400] “GET /international-chamber-of-commerce-icc-ud-754/ […]

A faster way to query custom post types with multiple conditions?

I am using a lot of custom post types (CPTs) with custom meta and so far I have been using queries like the below, to get for example all events in CountryX that happened in 2014: <?php global $paged; $curpage = $paged ? $paged : 1; $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘event’, […]

Limit scripts and styles on dashboard for user role

How can I properly prevent scripts and styles from loading on dashboard for some user role? My users need only access to one plugin and that’s the only thing they see on dashboard. How can I dequeue scripts for them?

Optimising uploads folder then re-uploading?

Rather than using a plugin to optimise images via the admin, would downloading and optimising locally work as well? As in would downloading the uploads folder, using something like ImageOptim to optimise all the images then re-uploading them work? Or for the site to take advanced of an optimised image does it need to be […]

Optimize slow SQL query for multiple meta values

Can you help me to optimize this slow query? The page containing this query is loading slowly: SELECT, b1.meta_value AS display_name, b2.meta_value as user_nicename, b3.meta_value as user_organization, b4.meta_value as user_tilte, b5.meta_value as user_street_address, b6.meta_value as user_city, b7.meta_value as user_state, b8.meta_value as user_phone, b9.meta_value as page_key, b10.meta_value as page_id FROM wp_users a INNER JOIN wp_usermeta […]

How can I use PurifyCSS to clean WordPress style.css?

I am trying to use PurifyCSS to clean my style.css file. When I try it on static html file if works fine. See example of my CLI command: purifycss wp01/wp-content/themes/mytheme/style.css index.html –min –info But when I try to use it on live web (running on my localhost) I am getting incorrect results. Here is my […]

Optimizing function that automatically creates internal links based on post title string

Problem sovled,thank you @SamuelElh for the tip ,so I relect it in the code.Transient turns out to be the right solution. I wrote a function that adds links to existing post titles that occur in a post. For example, when you add a post to a site with the title “this is a title” and […]

High traffic management in WP

I have to develop a site in WordPress similar to an already existing site in JSP which handles approx.50K users a day and 200 users at a time. And in load testing i get that wordpress can handle only 40 users at a time (with Super Cache plugin ON). Also I have hosted my site […]

Minimizing scripts & css files that plugins add

I try my best to limit plugin usage and only use ones that are well designed. But I still find that many will load a lot of extra scripts and styles, and few have options to load selectively based on whether the plugin is being used. I have started doing things like deregsitering the plugin […]