WordPress Database lost auto increment

I had a similar issue, I solved it and since this comes up high on Google for what I was looking for it may help others. I migrated several WordPress databases from AWS RDS MySQL to MySQL running on an EC2 instance, using the database migration service. What I didn’t know is it doesn’t copy … Read more

How to fetch Data in WordPress using MySQLi or $wpdb

To fetch data from database table <?php $results = $wpdb->get_results( “SELECT * FROM $table_name”); // Query to fetch data from database table and storing in $results if(!empty($results)) // Checking if $results have some values or not { echo “<table width=”100%” border=”0″>”; // Adding <table> and <tbody> tag outside foreach loop so that it wont create … Read more

Mysqldump add drop table?

It only affects the output of your MySQL dump in the file that is created. It isn’t necessary. It is just there so that if you import the created dump file into a database that already has a table with the same name, it will drop that table and then add the new table in … Read more

wpdb update add current timestamp not working

You seemed to have solved everything but the issue with the time: found the issue %d should be %s. but I see that it saves the server time not the current timezone WordPress has a number of date/time related functions. In this case, it sounds like what you need is current_time(), which… Returns the blog’s … Read more

MariaDB as a backend database

Yes, you can use MariaDB. MariaDB is a drop-in replacement for MYSQL so compatibility is not an issue. WordPress even lists MariaDB as an option within the requirements on their website: We recommend servers running version 7.2 or greater of PHP and MySQL version 5.6 OR MariaDB version 10.0 or greater. Here is a resource … Read more

How to get the post publish date outside the loop?

get_the_date must be used inside the Loop. For outside the loop use get_the_time. $posts = get_posts(array(‘numberposts’=>-1)); //Get all published posts foreach ($posts as $post){ echo get_the_time(‘Y-m-d’, $post->ID); //Echos date in Y-m-d format. } Consider replacing ‘Y-m-d’ in this example with get_option(‘date_format’) as this will display the date as per your date format setting in wp-admin.

Does dbDelta delete columns as well?

As far as I know, dbDelta() is primarily used to add tables to the database. It can also add or alter columns. To delete columns, you should use $wpdb->query(): global $wpdb; $table = $wpdb->prefix . ‘table_name’; $wpdb->query( “ALTER TABLE $table DROP COLUMN column_name” );

Detecting errors generated by $wpdb->get_results()

There is a class variable that stores the last error string – $wpdb->last_error. By the looks of the way $wpdb is coded, if the query succeeds, $wpdb->last_error will be an empty string, if it fails, it will be the error string returned by MySQL. So something like this would do the trick. $result = $wpdb->get_results(“SELECT … Read more