After Import: Insert “Use” Statement in Database

It appears, at least in cPanel, the lines in question were not required in the export, with the unsurprising consequence of the other encapsulated sql statements defaulting to reference the current database only. Turns out to be convenient when more than one database is configured, so long as there are no statements that select objects … Read more

How to generate PDF dynamically based on values from the database in WordPress

Using the FPDF library (found at http://www.fpdf.org) you generate PDFs on the fly using any data from your WP site. function wpse60844_generate_pdf( $post ) { /* Define paths for where the PDF will be permanently or temporarily saved */ define( ‘FPDF_PATH’, plugin_dir_path( __DIR__ ) . ‘/fpdf/’ ); define( ‘SAVE_PATH’, plugin_dir_path( __DIR__ ) . ‘fpdf/pdfs/’ ); … Read more

Do Seeded Orderby Rand Queries Benefit from DB Caching?

Looking at the source of class-wp-query.php (ie, the WP_Query code), I find this: /* * Ensure the ID database query is able to be cached. * * Random queries are expected to have unpredictable results and * cannot be cached. Note the space before `RAND` in the string * search, that to ensure against a … Read more

$wpdb->update is not working until next page refresh. Is there one more step?

When you use $wpdb->update in WordPress, it updates the database immediately, but WordPress might still show cached data. To ensure the updated data is displayed right away, you should manually clear the post cache using clean_post_cache($pid); after the update. Here’s the adjusted code: $pid = 55276; $post = get_post($pid); echo ‘original post:<BR>’.$post->post_excerpt.'<HR>’; $newtext=”some textt2″; global … Read more

Database Errors since site updated to WordPress 6.4.3

The errors were generated because there was a plugin that forced sql modes to be used on the database that are actually “incompatible” with wordpress. The following code was sadly executed for every request… private function set_sql_mode() : void { // Make sure no sql modes can be blocked (By wordpress built-in incompatible modes) add_filter(‘incompatible_sql_modes’, … Read more

How to reduce uncached page generation time?

there is no simple general answer for this, as it depends on what is causing the issue. Best way is to check your page using some Insights tool: https://pagespeed.web.dev/ https://gtmetrix.com/ They will tell you where the issue is. Big images are commonly a big issue – there are many converters to WebP format, that will … Read more

Sharing plugin tables between 2 sites in the same database

I’ve created an alternative wp-config.php and renamed to wp-config2.php with the same configuration except for the table prefix. Then I tried by editing all the plugin files. At the top of each file I found: if ( ! defined( ‘ABSPATH’ ) ) { exit; // Exit if accessed directly! } And I replaced it for: … Read more