1

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:

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

What is the error in my first query?

2

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.

  • Yep. That makes sense. It works now... THX – user998163 Sep 9 '13 at 19:05
1
$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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.