$wpdb->insert is not working

It sounds like it would be simpler to go back and fix your initial try: saving an option to a WP-native table rather than creating your own. Try update_option – it creates an option if it doesn’t exist, or updates if it does. This will save you a lot of code and headaches in the … Read more

Uppercase to sentence case for post titles

You can do that with a command in your database: UPDATE `wp_posts` /* Adjust the prefix! */ SET `post_title` = CONCAT( UCASE( /* First letter uppercase */ SUBSTRING( `post_title`, 1, 1 ) ), ”, LCASE( /* The rest in lowercase */ SUBSTRING( `post_title`, 2, LENGTH(`post_title`) ) ) ); If your author has a habit of … Read more

Show last modified date of database

There’s an UPDATE_TIME column in the TABLES table in the information_schema database. So you can try to get the max from that column with e.g.: SELECT MAX(`UPDATE_TIME`) FROM information_schema.TABLES WHERE TABLE_SCHEMA = ‘dbname’ where we replace ‘dbname’ with the corresponding database name. More related info here on SO. From the MySQL 5.7 docs: UPDATE_TIME displays … Read more

Does WordPress always create unique passwords?

Theoretically No! But practically Yes! Every new framework/CMS now implements some sort of library that adds randomness to the actual password. Its a randomly generated salt in form of a random string or time, etc. That is saved along with the hash password in database. Since theoretically, a collision can occur in any cryptographic function … Read more

Customize JSON output

This code will do the job: $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ); $query = new WP_Query( $args ); $posts = array(); $categories = array(); $json = array(); while( $query->have_posts() ) : $query->the_post(); $post_categories = get_the_category(); $post_category = current($post_categories); $categories[] = array( ‘name’ => $post_category->name ); $posts[] = array( … Read more

MySQL crashed because of the large number of requests

MySQL shouldn’t crash because of queries like those, but it could feel like it does because your site won’t work. I’d first run SELECT option_name, length(option_value) FROM wp_options WHERE autoload = ‘yes’ ORDER BY length(option_value) DESC; to see if some option has accumulated a large value (I’ve seen wp-cron entries grow very large in one … Read more

Show content from database

You could use custom post types and custom taxonomies. Using the custom post types to store data, taxonomies to categorize the data and you can utilize WordPress’ default searching functionality. https://codex.wordpress.org/Post_Types https://codex.wordpress.org/Taxonomies https://codex.wordpress.org/Creating_a_Search_Page

How to check if a core update, like 4.9.8 → 5.0, involves a database update (migration)?

So after some thinking I came up with this: Codex / WordPress Versions has Changelogs, but these seem to mention (recent) database upgrades implicitly, starting at 5.0. (Compare how Matomo explicitly states DB upgrades). Maybe this will be enough for future versions, here’s the thorough, cumbersome way that works for older versions, too: check db_version … Read more

How can I UN-orphan media files?

This is random, but a friend of mine got himself into the same situation a two weeks back and found this plugin to be helpful. https://wordpress.org/plugins/media-sync/ But as Tom mentioned above in his comment, you’ll run into attachment post type issues. Hope this helps you get half way there!!