Mixing variables into an array when inserting values

You are creating a string …. $sql=””ft_num”=>””.$ticket[‘number’].'”,”booking_id”=>”‘.$ticket[‘booking’].'”‘; … but expecting it to operate as an array… array( $sql, ‘event_id’ => $event[‘id’], This has nothing to do with how WordPress does anything. This is pure PHP. You have literally created this: array( [] => “ft_num”=>”‘.$ticket[‘number’].'”,”booking_id”=>”‘.$ticket[‘booking’].'”, ‘event_id’ => $event[‘id’], You need to build the array dynamically. $dynargs … Read more

How to stop $wpdb from prepending database name

The behavior I described in my post only happens when you are using $wpdb->update to execute an UPDATE statement. If you want to update a different database using the same connection, use $wpdb->query to send a raw query, WP won’t modify it then.

Update postmeta after theme switch

I am going to guess that you have your code in the theme, probably functions.php. That code will only load when the theme is active, and after_switch_theme only runs after the theme change. There is no before_switch_theme that I am aware of. You will need to have this code in a plugin or a mu-plugin … Read more

Why this query is not showing any result on wordpresss home page?

First of all your query is wrong. The right query is $mypost = $wpdb->query($wpdb->prepare(“SELECT post_content FROM $wpdb->posts WHERE ID = %d”, 2)); Second the $wpdb->query will returns an integer value indicating the number of rows affected/selected. You can check here http://codex.wordpress.org/Class_Reference/wpdb#General_Syntax If you want generic result you can use $wpdb->get_results http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results $mypost = $wpdb->get_results($wpdb->prepare(“SELECT post_content … Read more

Active DB queries in WordPress?

wpdb doesn’t include such kind of API, mostly since it descended from ezSQL which didn’t either (as far as I remember). While there are some helpers for insert/update stuff, most of query abstraction happens in WP_Query since that’s where bulk of complicated querying is typically going on.

How do i append UNION SQL Query with default search query

Append data to the native search: You can try for example: add_action( ‘pre_get_posts’, function( $q ) { if( $q->is_main_query() && $q->is_search() ) { $q->set( ‘nopaging’, true ); add_filter( ‘posts_request’, function( $request ) { $sql=”YOUR EXTRA SQL QUERY”; return “({$request}) UNION ({$sql}) ORDER BY post_status DESC”; }); } }); where we use the no paging version … Read more

Using ‘mysqli_connect’ ‘crashes’ WordPress client-side

Firstly, you could and should use wpdb to connect to another database. E.g. like this: $the_other_db = new wpdb( ‘username’, ‘password’, ‘database’, ‘localhost’ ); $results = $the_other_db->get_results( $sql ); Take a look at Using wpdb to connect to a separate database for more information. Secondly, like @AndrewBartel said it’s likely the plugin. Besides IMHO – … Read more

Custom WordPress Table wpdb

First off, you should not be handing an untrusted input (in this case, $_GET[‘id’] to your database. Always SQL-escape the query and validate/sanitize the data. (In the code snippet below, it’s SQL-escaped using $wpdb->prepare() for escaping and int typecasting to sanitize to integer value). Secondly, the $wpdb object provides more than just the query() function. … Read more