36
votes
Delete all posts of a custom post type—efficiently
You can delete all post via $wpdb
DELETE FROM wp_posts WHERE post_type='post_type';
DELETE FROM wp_postmeta WHERE post_id NOT IN (SELECT id FROM wp_posts);
DELETE FROM wp_term_relationships WHERE ...
22
votes
get_option() vs get_theme_mod(): Why is one slower?
The answer that yes, the theme_mod functions will be slower, but not significantly, and the benefits outweigh the differences.
Theme mods are stored as options. So, in essence, the theme_mod ...
18
votes
Any reason why wp_cache_set not to work?
The wp_cache_*() functions are non-persistent caches which means that they only last during the current page request. This would be beneficial if you're requesting the same information multiple times ...
14
votes
Wordpress so slow to load on MAMP
Go to wp-config.php, find the line below:
define('DB_HOST', 'localhost:8889');
And change it to:
define('DB_HOST', '127.0.0.1:8889');
Works like a charm!
11
votes
Accepted
How can I debug the TTFB in WP?
Meanwhile, I found some plugins and tools that can help with this:
Query Monitor
Laps
Debug Bar with some add-ons(Slow Actions, Rewrite Rules, etc.)
If you really wanna go deep, try using Webgrind.
...
11
votes
Accepted
How many posts can I have in a WordPress website?
2,000,000,000,000 WordPress posts, is it possible?
Simple answer, Yes. The days of 2GB size limit on file systems are gone. Now, you can literally have unlimited entries on almost everywhere if your ...
10
votes
Delete all posts of a custom post type—efficiently
This can now be done with the WordPress CLI using wp post delete. Once the CLI is installed, the following terminal command (while in your site's root directory) will delete all posts of type ...
9
votes
What's the difference between wp_insert_user() and wp_create_user()
As per Codex
The wp_create_user function allows you to insert a new user into the
WordPress database. It uses the $wpdb class to escape the variable
values, preparing it for insertion into the ...
9
votes
Delete all posts of a custom post type—efficiently
You can delete all posts of a custom post type in various methods but here I am gonna show you how to do this without using SQL query.
Here, for example, our post type is product
$allposts= get_posts(...
7
votes
Accepted
Is it true $wpdb->get_results is faster than WP_Query in most cases?
How can I prepare() my wpdb query? I tried but couldn't manage because
of the second parameter.
The prepare() works is explained in Codex, you need to have a query with placeholders and additional ...
7
votes
Accepted
Is security a problem in Wordpress?
In a general sense, any well maintained platform can be used to to create a website with good security. It has to be noted that you will never build a website which is completely secured against ...
7
votes
Accepted
WordPress tips for speed and performance
I work with several large WordPress sites, news sites specifically, that have thousands of posts and thousands of visitors (300k/day). With the stuff below, and a well coded theme, with well written ...
6
votes
Accepted
Multiple plugins vs combined one
If it's exactly the same code, then no - it shouldn't cause any performance changes...
Why? Because loading a plugin is pretty easy (hence quick) process. It all happens in wp-settings.php and this ...
6
votes
Is it useful to turn on MySQL query cache for performance
General speaking yes for read-only applications (until MySQL 5.7, it's deprecated since version 8.0), it enables equal SELECTs to return data extremely fast if identical calls are already stored in ...
5
votes
Accepted
Nginx FastCGI_Cache Vs PHP Caching
Nginx is really good at concurrency (PHP not so much) so you should try a bit more than 180 requests per second. Maybe 500, or 1000 depending on your server resources and network throughput.
The ...
5
votes
Accepted
Wordpress shortcodes & performance
You need to look at this from a couple of perspectives and then you have to weigh the odds against each other
In general, shortcodes will be slower (we are talking milliseconds here) as they need to ...
5
votes
How many posts can I have in a WordPress website?
Adding a little Rick Hellewell answer.
Creating some custom PHP/MySQL code to do it is a different thing than using Wordpress for it - the main difference is the table structure, which can be much ...
5
votes
Is 30 posts/sec considered slow for wp_delete_post?
Speed factor of any function that deals with content such as wp_insert_post() or wp_delete_post() highly depends on the situation and the content that it's dealing with.
Let's make a simple example. ...
5
votes
Accepted
Do multiple revisions really slow down WordPress?
Having 2 revisions or 100,000 will not change front end performance in a default plugin-less WordPress setup
However plugin and theme authors who do not query the database correctly, could end up ...
5
votes
Accepted
wp_redirection_404 table has grown to 7GB
That table is from the redirection plugin, and isn't a part of WordPress Core. Deleting it should have no ill effects as long as you disable the plugin too.
If you wish to continue using that plugin ...
5
votes
wp_redirection_404 table has grown to 7GB
This is a LOG table. It logs 404 errors - requests that Redirection could not resolve. The proper way to shrink the table is: change the setting "time to keep logs for" to something shorter than "...
5
votes
Accepted
Sample -- test -- data for large WordPress install
Few built-in wp-cli generate commands from the docs:
# Generate posts with fetched content.
# See https://developer.wordpress.org/cli/commands/post/generate/
$ curl -N http://loripsum.net/api/5 | wp ...
4
votes
Accepted
What effect does the_content filter have on performance?
The difference would be negligible.
The the_content filter is fired regardless of whether you use it or not because WordPress uses it for other things. So the only thing that would be performance ...
4
votes
Accepted
Disable slow media queries?
Solution for WordPress versions >= 4.7.4 (4.8)
Ticket #31071 introduces patches with new filters to override three possible slow media queries, in the wp_enqueue_media() function:
...
4
votes
Accepted
Improving the perfomance of a plugin action
Your original piece of code (the code from the previous question) did need some performance boost in the context it was given. As for the updated code, you will need to remove the fields parameter as ...
4
votes
Is it better to assign functions like get_the_id() to a variable if it's used multiple times?
Yes, it is always better to keep the result of a function call in a private variable. But the reason is not performance.
Reliability
In your example, you are calling a function that internally ...
4
votes
Accepted
Conditionally loading JavaScript based on the Advanced Custom Fields in the post
ACF has finegrained filters for fields when they get loaded.
add_action( 'wp_enqueue_scripts', 'register_my_scripts', 5 );
function register_my_scripts() {
wp_register_script( 'my-script', 'path-...
4
votes
WordPress website loads but is not displayed until page scrolled
I have visited your site in several browsers, including Chrome, and everything is working fine. The sole fact that you only experience the problem only in chrome, already means that this question is ...
4
votes
Uploading images to Media Library fails with Memory Exhausted
There is already a built-in function created just for that purpose. You don't need to write walls of codes to uploads images from your disk. You can use media_sideload_image instead.
This function ...
4
votes
Accepted
wp_register_script multiple identifiers?
To have the JavaScript Libraries not to load since you already created a bundle of them, do the following:
Asumming the following, usual enqueue:
function the_js() {
wp_enqueue_script('bundle_js'...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
performance × 582plugins × 59
database × 51
wp-query × 42
cache × 42
mysql × 34
optimization × 29
php × 22
javascript × 22
query × 22
css × 20
wp-admin × 20
plugin-development × 19
server-load × 19
custom-post-types × 18
posts × 16
ajax × 14
plugin-w3-total-cache × 14
memory × 14
functions × 13
post-meta × 13
multisite × 12
server × 12
nginx × 12
custom-taxonomy × 11