Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:17:38+00:00 2026-06-16T00:17:38+00:00

I have a perfectly working wpdb prepare statement before WordPress 3.5. This is my

  • 0

I have a perfectly working wpdb prepare statement before WordPress 3.5. This is my line:

$post_id = $wpdb->get_var($wpdb->prepare( "SELECT a.post_id
        FROM $metatable AS a
        JOIN $metatable AS b ON a.post_id = b.post_id
        WHERE a.meta_value = '$valuex1' AND b.meta_value = '$valuex2'"));

Now with WordPress 3.5, this returns a warning since this is not fully sanitized. I have modified this to use placeholders as advised by WordPress:

$post_id = $wpdb->get_var($wpdb->prepare("SELECT a.post_id FROM $metatable AS a JOIN $metatable AS b ON a.post_id = b.post_id WHERE a.meta_value =%d AND b.meta_value =%s",$valuex1,$valuex2));

However,it does not anymore retrieve the correct information from the database. Is there something wrong with my modified query? How to change it so that it will be working again?

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:17:38+00:00Added an answer on June 16, 2026 at 12:17 am

    My bad, this is so simple! WordPress uses two placeholders %s and %d.

    %s should be used when passing strings to the database

    while:

    %d should be used for integers.

    My problem above is that I’ve mixed them up, I use %d for strings or %s for integers. So the problem is resolved by using the correct placeholders for your specific data type. Problem solved.

    For example if you are querying the database using id with php variable $id, the placeholder should be %d because it’s integer otherwise for strings, such as names, etc. use %s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this below code before and was working perfectly. When I use
I have the following DML statement that is working perfectly, i have tried to
I have only started getting this error. The application works perfectly when working on
I have this letterpress effect with my own font and it is perfectly working
I have the following SQL statement which was working perfectly until I moved it
I have a (from what I can tell) perfectly working Linux setup (Ubuntu 8.04)
I have a MySQL View that is perfectly working: SELECT `t`.`TraderId` AS `TraderId`,`t`.`ShopName` AS
I have integrated Zxing library in my Android application, and it is Perfectly working,
I have rails app which are working perfectly in the local computer. But when
I have a user form that is working perfectly. The page makes use of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.