wpdb_prepare with multiple or condition

I want to execute a query like this:

$wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )..., $string );

If I do the query with only one condition it works:

Read More
$wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' )..., $string );

What is the error in my first query?

Related posts

2 comments

  1. 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.

  2. $like = '%'. $wpdb->esc_like($searchExpression) . '%';   
    
    $sql_content =  $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE (     post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )", $like, $like );
    $post_id = $wpdb->get_var($sql_content);
    

    this worked from
    credits user998163

Comments are closed.