40 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 ...
pathusutariya's user avatar
22 votes

Any reason why wp_cache_set not to work?

As of WordPress 6.3, both WP_Query and WP_User_Query automatically cache requests. The original question example is outdated since get_posts() uses WP_Query. The wp_cache_*() functions are non-...
Howdy_McGee's user avatar
  • 20.6k
16 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 ...
jwinn's user avatar
  • 261
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!
user112547's user avatar
12 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(...
Saruque Ahamed Mollick's user avatar
12 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 ...
e4rthdog's user avatar
  • 451
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 ...
Johansson's user avatar
  • 15.3k
10 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. ...
Narayon's user avatar
  • 291
10 votes
Accepted

Disable lazy loading on specific images

You can manage WordPress lazy loading with the loading parameter. Below code echo's your image without using the lazy load function. echo wp_get_attachment_image( $image, $size, false, [ 'class' =&...
DeltaG's user avatar
  • 899
8 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 ...
Pieter Goosen's user avatar
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 ...
Tyler Johnson's user avatar
6 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 ...
Tom J Nowell's user avatar
  • 59.2k
6 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 "...
Bilbo's user avatar
  • 161
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 ...
Krzysiek Dróżdż's user avatar
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 ...
middlelady's user avatar
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 ...
kovshenin's user avatar
  • 2,583
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 ...
Picard's user avatar
  • 1,145
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. ...
Johansson's user avatar
  • 15.3k
5 votes
Accepted

Why can't /wp-login.php be load balanced?

A few things to check on: Review wp_salt. Make sure all of the web servers are running on the same set of salts in the wp-config.php file. Ideally, these should be mirrored from a single location. ...
jaswrks's user avatar
  • 851
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 ...
David Sword's user avatar
  • 3,327
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 ...
birgire's user avatar
  • 67.1k
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 ...
fuxia's user avatar
  • 107k
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-...
JHoffmann's user avatar
  • 1,830
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 ...
cjbj's user avatar
  • 14.5k
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 ...
Johansson's user avatar
  • 15.3k
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'...
David Lee's user avatar
  • 3,861
4 votes

Defer Code in Widgets - Page Speed

This has nothing to do with WordPress. It's about browser behaviour in loading scripts. You are right in noting that defer will not work with inline scripts. So, the easiest approach is to add an ...
cjbj's user avatar
  • 14.5k
4 votes

Defer Code in Widgets - Page Speed

@cjbj is right, I upvote him. However, you can try another approach if you want - move that script into a file (i.e. wp-content/your_script.js) and then insert it into widget with defer: <script ...
T.Todua's user avatar
  • 5,789
4 votes
Accepted

Stop all SQL_CALC_FOUND_ROWS wordpress queries

Using Query Monitor I was able to find the source of this query, it was from a plugin "starbox" which uses the query to fetch the last 3 posts from the author of a given post. Editing the plugin by ...
user178785's user avatar
4 votes
Accepted

Which is faster wpdb & get_row or wp_query & ge_post_meta?

You should always use get_post_meta. Your attempt to micro-optimise using a raw SQL query will reduce not improve performance. When you fetch a post, WordPress bulk fetches its meta for performance ...
Tom J Nowell's user avatar
  • 59.2k

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