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

Is there a plugin that will override the “Error establishing a database connection” message? [closed]

http://yoast.com/custom-wordpress-database-error-pages/ You can make your own Database Error page by adding a db-error.php to your wp-content folder (/wp-content/db-error.php). You can find a good example of such a page in the link above. Don’t forget adding header(“HTTP/1.0 500 Internal Server Error”); in that file so it get a proper header message.

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” );