Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
23

1. Set the query before WP_Query is run This seems to be the most important thing to keep in mind when trying to keep database queries to a minimum since the only opportunity to alter the query is, of course, before it is run in the SQL database. Normal Queries For a normal query, WordPress uses the wp() function, which in turn calls $wp->main( $...


14

Excellent responses on WP Hackers: http://lists.automattic.com/pipermail/wp-hackers/2012-June/043213.html What you're doing with that query, is loading EVERY matching post into memory, including the full post contents. As you can imagine, this is probably quite a lot of items. You can pass 'fields' => 'ids' into WP_Query to simply return a list ...


10

I would indeed switch to InnoDB. Table locking/row locking has long been discussed by many. I would always choose InnoDB hands down. However, there is another profound reason for choosing InnoDB...CACHING. While most people boast that MyISAM is faster for reads, most people forget that the many cache for MyISAM, which is called the key cache (set by ...


9

It did appear that the json wasn't being cached by wp-super-cache, but we decided to take a different approach. By using the transient api, we were able to do a faux-cache on all json, and drastically reduce the taxing of the database. Then on the ajax side of things, we are caching the html that is created from this semi-cached json. Things are super speedy!...


9

I know it might be abit late for answer but I came across similar issue while making my test project. Here's how I solved it. /* apply this filter only on relevant to you pages */ function mb_bail_main_wp_query( $sql, WP_Query $wpQuery ) { if ( $wpQuery->is_main_query() ) { /* prevent SELECT FOUND_ROWS() query*/ $wpQuery->...


7

If possible get your PHP updated to the 5.4.x branch. Before you add your caching layer you need to determine whats slowing down MySql and PHP. You need to enable WP_Debug and eliminate any PHP errors. Look for undefined indexes, syntax errors and deprecated functions. That 20 second to first byte is all PHP, MySql and or WordPress related. It sounds ...


7

Caching the WordPress Menu also gives you a performance boost. Especially if you have a lot of Pages or a giant Menu Structure, this should be considered. Do it in 2 easy steps. At first, create a function that gets or creates the menu, instead of calling wp_nav_menu directly. function get_cached_menu( $menuargs ) { if ( !isset( $menuargs['menu'] ) ) {...


7

It's really simply GoDaddy and slow mysql and webservers. I've heard apocryphal stories of people making lots of noise to GoDaddy support and as a result, speeds improve. Do they get moved to better servers or get priority load-balancing? Impossible to say. One other thing to try is http://wordpress.org/extend/plugins/use-google-libraries/ but sometimes it ...


7

Siege. Test against both an actual post/page (which would theoretically hit page cache, APC, varnish, etc. for every request after the first request), and against a 404 (e.g., randomly generated strings), which would require database queries on each hit. A few helpful flags: -b benchmark (don't wait between requests) -c N where N is the number of ...


7

Keep in mind that the $content_width global is not only used for images, but also for embedded objects, such as video. So, any solution won't merely be a case of dropping use/support of $content_width itself. Usually a Theme will constrain content-area images in a few ways: Large Image size: Defining $content_width something appropriate for the Theme ...


6

WP Super Cache examines your WordPress site's pages for some HTML tags before it caches them. Your pages most probably don't have </html> tag (common issue), in that case, try adding something like //</html> -- that's a workaround, and WP Super Cache should then generate cached versions of your pages. Why does WP Super Cache do it like that? ...


6

I'm probably overcomplicating things. Right now, you are. As I have no traffic as of now I don't really need to do this, but .... I don't know what to choose as I don't understand what these services really do, other than it's supposed to be "better" to host externally... Then why bother with a CDN right now and all of the image hosting options ...


5

you probably won't manage to reduce ram usage that much. But if you're using mod_php, you may want to switch to mod_fcgid instead. while mod_php is slightly slower, it loads php even when it doesn't need to, such as serving images, static files, or even caching. If you have lot of requests, this is lot of ram. using fcgid will reduce this a lot. also, ...


5

This is not an amount that is likely to cause performance issues. However if you are concerned about leftover transients it is worth looking into if any code you are using is consistently "leaking" them (creating transients that are never removed). See Are transients garbage collected? for relevant discussion and some code snippets.


5

This is nonsense. Almost all URL getters are a result of get_option(), eg. get_option('stylesheet_root'), get_option('template') and so on. These options are loaded very early during the request, they are cached and not fetched again. Since the options are fetched anyway, all you can improve is processing time. Nanoseconds. This isn’t worth the trouble. ...


5

Completely canceling main query is pretty much high level madness, that involves subclassing wp class. I would: Hook into pre_get_posts with is_main_query() check Run featured query (still inside hook) and stash results somewhere Use those results to set excluded posts on main query


5

If you're building something for public consumption (a plugin, a theme, etc) use admin-ajax.php like you should because that is the appropriate and accepted way to do things and gives your end users the power they need to change and modify things if they so choose. Beyond that, the best you MAY be able to do is use the SHORTINIT constant. Define it in a ...


4

You have to balance speed optimization with reality. That means don't obsess over speed analytics, there is one thing you should be looking at in terms of satisfying users, load time (in most cases). Test your page un-cached and then cached, you should see a noticeable difference in how fast they load, for me your site is loading around 2.5 seconds, that ...


4

I prefer not to use GoDaddy because I always encounter performance issues. However, one of my clients is rather insistent on using them... so we are. This is exactly what I do in reverse , I insist that if they want to stay with godaddy they can find another developer/designer.


4

Godaddy is to blame. I think a monkey does everything manually whenever we submit a request for anything. Be it a password change or anything, it will take several minutes before anything happens. Monkey is so busy dealing with everything. Other than that they throttle their FTP connections, limit number of concurrent FTP connections, always have permission ...


4

For a highly trafficked site, you should tune all MySQL buffers for the content that is in place now. Regardless of the version of WordPress, the MySQL layer can have its configuration computed. In fact, if you have InnoDB data without enabling innodb_file_per_table, you need to cleanup InnoDB by segmenting each table into its own physical tablespace. It is ...


4

I've seen many more complaints about W3TC than WP Super Cache: WordPress › WP Super Cache « WordPress Plugins. W3TC loads the .htaccess file with many directives and tends to conflict with server side settings. With Super Cache, try PHP caching and follow the instructions to add an .htaccess file to the cache directory: http://wordpress.org/extend/plugins/...


4

Your specific questions: 1) There is no strict limit to the "number of entries" a DB may contain before performance is affected. Performance depends just as much on your hardware and configuration as it does on the size and structure of the DB. 2) If you're worried about the scalability of your DB layer, you can run it in a cluster, or on a cloud box or ...


4

Strictly from a MySQL Point-of-View, I have suggestions on how to improve caching of data/indexes for a MySQL Instance. Keep in mind that there are two major Storage Engines for MySQL MyISAM InnoDB Their caching mechanisms are different. There is something that you can do to tune for the Storage Engine of your choice. MyISAM MyISAM only caches index ...


4

get_posts() uses the WP_Query class to fetch posts. Usually, it returns an array of post objects. The $fields parameter for WP_Query accepts two valid arguments: 'ids' will make it return an array of post IDs and 'id=>parent' will make it return an associative array with the post objects properties as key => value pairs. Any other input value as an ...


4

wptexturize() (in wp-includes/formatting.php) tries to convert typewriter quotes " and ' into typographically correct pendants like “ or «, depending on current translation files. If you cannot type correct quotes, you should not disable it. There are some related replacements for dashes and ellipsis (not localized for whatever reason). All these ...


4

The only generic semi-automatic procedure I can think of would be to delete post meta where the post_id is invalid. SELECT * FROM {$wpdb->postmeta} as pm LEFT JOIN {$wpdb->posts} as p ON pm.post_id = p.ID WHERE p.ID IS NULL I wrote a SELECT and not a DELETE because I don't trust that to work in all cases. I have seen "dummy" or "placeholder" ...


4

It depends on local factors and actual usage patterns. Bigger queries require more memory to store the data and potentially, depending on the plugins you use, to process it into the response, therefor you are more in a risk of running out of memory. With Bigger response (i.e. bigger page HTML) it takes more time to transfer the page to the browser making the ...


4

Query Monitor will show you what is loaded or you can print them directly. function print_wp_scripts_queue(){ $scripts = wp_scripts(); echo "<pre><h1>scripts</h1>"; print_r ( $scripts->queue ); echo "<h1>todo</h1>"; print_r ( $scripts->to_do ); echo "<h1>done</h1>"; print_r ( $...


4

Have a look at the meta_query_find_compatible_table_alias filter defined in wp-includes/class-wp-meta-query.php. This filter's documentation: /** * Filters the table alias identified as compatible with the current clause. * * @since 4.1.0 * * @param string|bool $alias Table alias, or false if none was found. * @param array $clause ...


Only top voted, non community-wiki answers of a minimum length are eligible