Localize strings from db

There are multiple ways to do this: 1. Add multiple columns to the table with the strings you have to localize. E.g. one column for German, one for English, and so on. And then get the string from the appropriate column. This is perfect if the number of languages stays more or less constant (you … Read more

Improving wpdb queries with large data

Caching is Your Friend I understand your frustration with adding another plugin, but a method for extending WordPress cache is highly recommended for any WordPress sites getting any kind of traffic. These plugins allow WordPress to store cache somewhere better suited for storing and quickly accessing this data, such as Memcache, Redis, or even in … Read more

I have include wp-config, should I add global $wpdb also?

If you need a processing endpoint with access to the WordPress API, use the admin_post_ action and eliminate the need to manually include wp-config.php or any other WordPress files. // add for logged-in visitors add_action( ‘admin_post_your_action’, ‘prefix_your_action_function’ ); // for non logged-in visitors add_action( ‘admin_post_nopriv_your_action’, ‘prefix_your_action_function’ ); function prefix_your_action_function() { global $wpdb; // your processing … Read more

How to get Attachments(image) with specific width\height ratio

The _wp_attachment_metadata stores serialized data. It’s not meant to be used directly in queries to match results. Instead hook add_attachment action and store original image’s dimensions into separate post meta properties. After you’re happy with how it works follow Rarst’s advice and find a way to walk all existent image attachments and generate those meta … Read more

Weird characters displayed when importing WordPress MySQL db

Can you try setting the DB Charset within wp-config.php? define(‘DB_CHARSET’, ‘utf8_general_ci’); define(‘DB_COLLATE’, ‘utf8_general_ci’); Have a read of this first though: https://codex.wordpress.org/Editing_wp-config.php It can cause problems to an already existing blog to add those lines into wp-config.php, so use with caution. Are you importing this through WordPress or manually through something like PhpMyAdmin? Also, are all … Read more