MySQL queries in WordPress

I found the errors thanks to the help from @Milo @Milo’s query on catno pointed me to my error with my first query involving catno, and I also noticed a double equals in $catno == $row[0]; when it should be $catno = $row[0]; Final coding is function QueryStock($cat) { $query = “SELECT * FROM stock … Read more

Query Custom Fields in Searchform

Option 1 – Grab the post ID at the same time You can also select the post_id field when you running your query, allowing you to then get the post with a call to get_post($values->post_id); (if required). global $wpdb; $query = $wpdb->prepare(‘ SELECT p.post_id, p.meta_value FROM %1$s AS p WHERE p.meta_key = “post_views_count”‘, $wpdb->postmeta ); … Read more

Creates only one table and not the other

dbdelta demands that: You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY. You must … Read more

Plugin with connection to database – Single function

Use a global. So, your plugin file would look like this: $myConn = new wpdb( ‘username’, ‘password’, ‘database’, ‘localhost’ ); function plugin_step_1( $arg1, $arg2 ) { global $myConn; //code to do stuff here } function plugin_step_2() { global $myConn; // more code here } function plugin_step_3( $arg1 ) { //I don’t need the wpdb object … Read more

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