DROP TABLE IF EXISTS `wp_options` error?

Check this ref. If you don’t have the database create instruction inside your script: CREATE DATABASE your_db; You need to manually do that. Else if you have the database: use this to select it first before executing the script. USE your_db;

Attach posts based on category and position

I’m wondering if you’re actually looking at post revisions. Keep in mind that WordPress creates a revision of a post any time you make a change to it. Each revision stays in the database, however, the way you access it is by going into the post itself and then locating the revision section in the … Read more

Log IP of users who click a button? [closed]

It depends on how the button works. For instance, you can make an API. When the button is clicked, you can call the api via Ajax and save the IP during the process. Or most likely you will write ip via action hook, if the button call the hook. In this case, you will use … Read more

Prevent creation of unused database tables?

I’m afraid it won’t be easy to do (if possible at all). These tables are empty and you don’t use them, but… There are still many SQL queries that use them in JOINs. It means, that if you remove these tables, these JOINs queries will cause errors. There are many functionalities in backend, that use … Read more

How do join in query with WordPress

I have one solution global $wpdb; $db= $wpdb->prefix.’booking’; $dbAdditonal= $wpdb->prefix.’booking_additionals’; $booking = $wpdb->get_results(” SELECT b.*, IFNULL(GROUP_CONCAT(ba.NamePack SEPARATOR ‘<br />’),’N/A’) Extras, FORMAT(IFNULL(SUM(ba.Price),0)+IFNULL(b.Price,0),2) AS Total FROM $db b LEFT JOIN $dbAdditonal ba ON b.Id_Booking = ba.Fk_IdBooking GROUP BY Id_Booking “,ARRAY_A);

$wpdb->get_var returns 0

Your count for that query may be 0. Make sure $wpdb->tablex is correct. Also, definitely use $wpdb->prepare $user_followed = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT( * ) AS total FROM {$wpdb->tablex} WHERE type = %d AND active = %d AND user_id = %d”, 4, 1, $user_id ) );