Location of WP default mySQL tables creation file?

The SQL used to create the default tables is located in wp-admin/includes/schema.php inside wp_get_db_schema(): /** * Retrieve the SQL for creating database tables. * * @since 3.3.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $scope Optional. The tables for which to retrieve SQL. Can be all, global, ms_global, or … Read more

wpdb query not working

It’s probably because you must use % sign for “like” so it would be: SELECT * FROM `wp_usermeta` WHERE meta_key= ‘referrer’ AND meta_value LIKE ‘%270%’ AND meta_key= ‘view_type’ AND meta_value LIKE ‘%invoice%’

Valid SQL query not returning results

Here you’ve did something wrong with $wpdb->table_name. It will only return the default WordPress table names. Not custom table names. And also when you call $wpdb->prepare then pass the parameter as array. So your function will be like below- function get_info($postid) { global $wpdb; // Here I assumed that your table name is ‘{$wpdb->prefix}places_locator’ $sql … Read more

exclude pingbacks from wordpress SQL query

You can achieve this by excluding pingback from the comment_type column of wordpress comments table $query = “select wp_posts.*, coalesce(( select max(comment_date) from $wpdb->comments wpc where wpc.comment_post_id = wp_posts.id AND comment_approved = 1 AND post_password = ” AND comment_type NOT IN ( ‘pingback’ ) ), wp_posts.post_date ) as mcomment_date from $wpdb->posts wp_posts where post_type=”post” and … Read more

WordPress SQL search, how to handle SQL Injection?

The default public search query variable is s but not q. So when you use q, on a vanilla WP install, no posts filtering is done, as expected. You don’t have to take care of possible SQL injections, for the default search query, as it’s taken care of by the core. Here’s an example when … Read more

$wpdb->prepare affecting the query?

You can use the array directly because the $wpdb->prepare() method can be called like vsprintf(), which works like sprintf() but accepts arrays of arguments. $post_types = get_post_types(); unset( $post_types[‘attachment’], $post_types[‘nav_menu_item’] ); global $wpdb; $replace_query = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM $wpdb->posts WHERE post_type IN ( %s )”, $post_types ), ARRAY_A ); The problem with your … Read more

wordpress site – using custom database and PHP

Since we do not know how the data should be represented on the ‘front-end’ (read WP install), it is hard to say. You could convert the existing database to use custom tables. Create a small REST(1) JSON/XML(1) API(1) on the ‘other’ application. Then code a WordPress plugin that shows the data from the API with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)