wpdb_prepare with multiple or condition

I think your first partial code be this partial code: $wpdb->prepare( “SELECT * … from … WHERE ( post_title LIKE ‘%%%s%%’ or post_content LIKE ‘%%%s%%’ )…, $string, $string ); You have to have to pass the same number of arguments into the query as you specify (with %s) in it.

get the number of queries made on a page(inside my plugin)

$wpdb counts the queries ran and saves the value in the $num_queries class variable. $num_queries The number of queries that have been executed. https://codex.wordpress.org/Class_Reference/wpdb All you need to do is retrieve it: echo $wpdb->num_queries; You may also be interested in the $queries class variable. $queries You may save all of the queries run on the … Read more

How to use IN array properly in WordPress?

You need to have your replacement placeholders matching the number of values in your array, and then you can use the array as one of the prepare arguments. Proof of concept: $a = array(‘course_3202′,’course_3201′,’course_3200′,’course_3199′); $b = array_fill(0,count($a),’%s’); $b = implode(‘,’,$b); $sql = “SELECT * FROM $wpdb->postmeta”; $sql .= ” WHERE meta_key IN ({$b}) and meta_value=1″; … Read more

Cannot update custom database table row

Before trying to write to the database, always validate the values you’re putting in: $fValid = true; if ( !isset( $payment->status ) ) { echo ‘Error: Payment status is not set’; $fValid = false; } if ( !isset( $order_id ) ) { echo ‘Error: Order ID is not set’; $fValid = false; } if ( … Read more

How to prevent $wpdb->prepare stripping a leading zero in variable value?

Try this: $order_id = 012345; $sql = $wpdb->prepare(“SELECT payStatus FROM test_table WHERE ref = %s”,$order_id);//<– this doesn’t work var_dump($sql); echo ‘<br/>’; $sql = $wpdb->prepare(“SELECT payStatus FROM test_table WHERE ref = %d”,$order_id);//<– this doesn’t work var_dump($sql); echo ‘<br/>’; $sql = $wpdb->prepare(“SELECT payStatus FROM test_table WHERE ref = %f”,$order_id);//<– this doesn’t work var_dump($sql); echo ‘<br/>’; $sql = … Read more

WP Database Table to CSV file

You’ve got a few things wrong. The first is that you are clearly in WordPress context. You should be using the AJAX API for this rather than including wp-load.php. That is virtually never the right way to do it. get_results() defaults to an object, so you are going to get errors when you try to … Read more

Need help writing a $wpdb query

Is this what you’re trying to do? // WP_Query arguments $args = array ( ‘post_type’ => array( ‘project’ ), ‘meta_query’ => array( array( ‘key’ => ‘meta_key’, ‘value’ => ‘%$query%’, ), ), ); // The Query $query = new WP_Query( $args );

Why doesn’t my insert query work?

You have the following for the table name: $wpdb->prefix . “wp_list_press” Check your actual prefix and table name. In a WP installation using “wp_” as the prefix, the above would result in “wp_wp_list_press”. Is that the table name in the db or is it just “wp_list_press”? If the table in the db is “wp_list_press” then … Read more

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